各种语言的Andr​​oid的strings.xml,情景情景、语言、Andr、oid

2023-09-06 11:01:10 作者:夜微凉ミ雨轻伤

我有一个问题的strings.xml

I have a strings.xml question

我的应用程序是英文的。

My app is in english.

价值/ strings.xml中是英文

有许多其他语言的应用程序太

there are many other languages in the app too

我最新的字符串键添加在值恩/ strings.xml中,在英语语言环境中的文件夹,而不是在默认的语言文件夹

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?

这是棘手的我,因为它不是在默认值xml文件

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

感谢您的见解。

推荐答案

想象一下琴弦系统作为一系列if条件。首先,我们检查用户的语言,一旦我们有我们检查,看看是否该特定语言的文件夹包含了我们正在寻找的字符串。如果确实如此,我们返回该字符串,否则我们默认勾选值文件夹中。

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();
}

如果一个字符串值,属于恩和西班牙用户查找它,他们不会有机会检查值-en文件夹,因为他们没有资格获得它。另外,价值观文件夹默认将总是选中所以把它放在那里将为所有语言

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