Gaurav
Gaurav

Reputation: 13

How to dynamically modify localization values in android app

We want to implement the following requirement for localization -

  1. The parameter values stored in strings.xml (and other language variants) need to refreshed periodically (almost daily). This is because of some dynamic texts that needs to be displayed based on the language. The entries in the strings.xml can be added, modified or deleted. The values are fetched periodically (based on defined refresh policy) from a backend api call. If my understanding is correct, then we cannot modify the strings.xml dynamically in the apk file.

We are comtemplating 2 possible approaches -

  1. Make use of the device DB and load values from there (personally I dont like this approach very much as I am not able to predict the impact on performance. Any comments? )

  2. Create a wrapper implementation to parse xml's and have these values stored in the specific xml.

Depending upon the language selected parse the corresponding xml and use that to populate the map. The values are then fetched from this maps (in place of android Resource file)

If anybody who has faced similar issues, can you please provide your inputs and possible approach. If there is something default in Android api that I am missing and can be used in this situation ?

Looking forward to people's input on the above.

Upvotes: 1

Views: 1787

Answers (1)

Eric Cloninger
Eric Cloninger

Reputation: 2260

The problem is you need to depend on Android's ability to discover the correct localization based on locale, screen size, orientation, etc. These are conditions that are outside of your ability to influence and you don't want to try to reproduce the search logic.

Perhaps you could put a tag string in each of the individual string.xml files. This tag would have a keyword, perhaps the name of a table that is filled at runtime with your translated strings.

Upvotes: 1

Related Questions