Multilingual Android App Content

I enjoy developing an Android application with multilingual content. the content must be dynamically loaded from the database.

What's the best approach?

  • Do you have a separate database for each language? (e.g. content_en.db, content_de.db)
  • Fields for each language in the table? (e.g. name_en, name_de, ..)

thanks Peter

+3


source to share


3 answers


In your case, I suggest making separate tables for each language.

One of the main benefits you'll get: Assume that in the future you want to add support for another language, you can just create a new table for that rather than edit just one and end up messing it up.



For more information, you can refer to this question.

+1


source


Having a separate database for each language is easier, in my opinion easier. This is also a perfect use case for Dependency Injection . Let me explain why.

Let's say you want to support English, German and Spanish. All you have to do is create one common database structure. For each language, you create an instance. Let's take a look at the 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, the only difference is the name of the database. This is great for Dependency Injection, because from the outside you only have an object Database

. Next, you use each database in the same way, for example:

Database db = getDatabase("es");
List<String> cites = db.getCites();

      

Please note that Android resources you also have "individual database", such as values

, values-de

, values-es

, etc., where you store the data in the "Tables", such as strings

, dimens

, colors

, etc. that have the same name in everyone values-xx

.

0


source


Using a single database and table with a different language-based column is sufficient.

0


source







All Articles