android strings.xml in various languages, scenario

六眼飞鱼酱① 提交于 2019-12-23 03:07:20

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/14984659/android-strings-xml-in-various-languages-scenario

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!