Reputation: 301
I like to develop an android app with multilanguage content. the content should be dynamically loaded from a database.
Which approach is the best?
thanks Peter
Upvotes: 3
Views: 622
Reputation: 1165
Having a separate database for each language is easier to maintain in my opinion. It's also ideal case to use Dependency Injection. Let me explain why.
Suppose you want to support English, German and Spanish languages. All you need to do is create one common database structure. For every language you create instance. Let's look at some conceptual code:
public Database getDatabase(final String lang) {
switch (lang.toLowerCase()) {
case "en":
return openDatabase("content_en.db");
case "de":
return openDatabase("content_de.db");
case "es":
return openDatabase("content_es.db");
default:
throw new RuntimeException(String.format("Language \"%s\" is not suported.", lang));
}
}
As you can see, only difference is in name of the database.
For Dependency Injection it's great because from outside you have only Database
object.
Further you use every database in the same way, for example:
Database db = getDatabase("es");
List<String> cites = db.getCites();
Notice that in Android resources you also have "separate databases" such as values
, values-de
, values-es
etc. where you keep data in "tables" such as strings
, dimens
, colors
etc. which have the same names in every values-xx
.
Upvotes: 0
Reputation: 1278
In your case I would suggest making separate tables for each language.
One of the major benefits you will get is, Suppose sometime in future you want to add support for another language you can simply create a new table for that rather than editing the only one and eventually mess up the whole thing.
For further information you can refer to this question.
Upvotes: 1