10

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?

Jin35
  • 8,602
  • 3
  • 32
  • 52

3 Answers3

3

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

Community
  • 1
  • 1
Marek Sebera
  • 39,650
  • 37
  • 158
  • 244
  • The problem of this solutions - you can't refer to database from xml files, and you can't use standart 'Context.getString()' methods. – Jin35 Feb 20 '12 at 17:21
  • Yup, that's the dark side of solution, but as long as you will want to use your provided solution, there is no difference, only this is clearly more separate from system and it is more easy and lite to implement. – Marek Sebera Feb 20 '12 at 17:26
  • And can I create, for example folder `values-de` in my resources and put new xml file there? – Jin35 Feb 20 '12 at 17:31
  • as you cannot edit files saved inside of `.apk`, no, this isn't possible. – Marek Sebera Feb 20 '12 at 18:59
3

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.
Jin35
  • 8,602
  • 3
  • 32
  • 52
0

Overriding the standered resource/language using resource files which are complied time then your scarifying performance over customization. Do it only if u need this.