Reputation: 5624
I'm working on an application where I would like to ship it with some custom data in a database. Among some numeric id's and codes I would also like to ship strings with the application. Storing the strings in the database seems to be a bad idea however since I would like to localize the application into other languages and thus I should store all strings in strings.xml files for localization purposes. The strings are however closely related to the id's and codes in the database so I need some type of relation between them.
Is it possible to store a reference to the string resource in the database? Or is it a better idea to store all translated strings in the database and add a language-code column where the code could be stored in the strings.xml files and be different for each language?
The language-column approach would certainly work but the localization would be spread out in different parts of the application which I am not sure is good design.
Upvotes: 2
Views: 1778
Reputation: 3248
You should be able to just specify the string's name attribute in the database, and then, when loading from the database, you could use:
getResources().getString(getResources().getIdentifier("string_name", "string", "com.package.myapp"));
This should retrieve a localized string.
Upvotes: 7