CQM
CQM

Reputation: 44278

android strings.xml in various languages, scenario

I have a strings.xml question

My app is in english.

values/strings.xml is in English

there are many other languages in the app too

my latest string key additions are in values-en/strings.xml , the english locale folder , but not in values the default language folder

how will this affect a non-english user that loads a view which tries to access the strings only defined in values-en? will the OS find the string in that one file and display it in english?

this is tricky to me because it is not in the default values xml file

thanks for the insight

Upvotes: 1

Views: 1932

Answers (1)

jimmithy
jimmithy

Reputation: 6380

Imagine the strings system as a series of if conditions. First we check the language of the user, once we have that we check to see if the folder for that specific language contains the string we are looking for. If it does, we return that string, otherwise we check the "values" folder by default.

if (language.equals("en") {
   stringsFolders = "values-en";
} else if (language.equals("es") {
   stringsFolders = "values-es";
} 

if (stringsFolder.contains(key) {
    return stringsFolder.get(key);
} else if ("values".contains(key) {
    return "values".get(key);
} else {
    throw CantFindException();
}

If a string belongs in values-en and a spanish user looks for it, they will not have the opportunity to check the values-en folder because they don't qualify for it. Alternatively, the "values" folder is always checked by default so placing it there will work for all languages

Upvotes: 1

Related Questions