Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can localization resources be downloaded in runtime?

I have application with internet access and don't want to store many string.xml files for different languages.

What I want:

  1. Application contains only one string.xml with english strings.
  2. When user launches it - I see user's phone locale, and ask my own server for necessary language file. (resource keys will be the same)
  3. When new resource file comes, all interface should work with new file.

The question is how to change existing or add new string.xml file in runtime?

like image 705
Jin35 Avatar asked Feb 20 '12 17:02

Jin35


People also ask

What is resource localization?

Localization is the process of translating an application's resources into localized versions for each culture that the application will support.

How localization works in Android?

In order to localize the strings used in your application , make a new folder under res with name of values-local where local would be the replaced with the region. Once that folder is made, copy the strings. xmlfrom default folder to the folder you have created. And change its contents.

How do I set default resources while localizing an app?

Right click on it, then choose New ▸ Android Resource Directory. This opens the New Resource Directory window. From there, you can select the resource type and qualifiers you want to create. For localization of strings, add a new directory with a values resource type and a Locale qualifier.


2 Answers

Now I can see only solution:

  1. Create some "localization proxy" that will return me necessary resource (from string.xml or downloaded resource)
  2. Replace all getString() and getText() to your own method getStringFromLocalization
  3. Override TextView, Button and some other views with custom one and change there init and setText methods.
like image 99
Jin35 Avatar answered Oct 11 '22 12:10

Jin35


You obviously cannot change, download or remove strings.xml at runtime

If you want to store locations, you will have to use SQLite storage to store translations.

similar:
How to modify strings.xml file at runtime
run time modification of strings.xml

like image 42
Marek Sebera Avatar answered Oct 11 '22 14:10

Marek Sebera