安卓.如何对一个国家/地区的所有语言使用相同的可本地化消息? [英] Android. How to use the same localizable messages for all the languages in a country?
问题描述
我的国家(西班牙)有几种语言(es-ES,ca-ES,gl-ES,eu-ES).我们暂时不会添加所有语言,因此我们想在西班牙使用主要语言,即西班牙语.当用户选择该国家/地区中的其他一种语言时,我们希望显示/values-es/strings.xml
.我们该怎么做?
My country (Spain) has several languages (es-ES, ca-ES, gl-ES, eu-ES). We won't add all the languages for now so we would like to use main language in Spain, i.e. Spanish (es). We would like to display the /values-es/strings.xml
when the user has selected one of the other languages in the country. How can we do that?
哦,我们想使用英语作为默认语言(/values/strings.xml
).
Oh, and we would like to use English as the default language (/values/strings.xml
).
拥有/values-ES/strings.xml
之类的东西会很棒,但是我想那是不可能的,因为第一个代码应该是语言代码.
It would be great to have something like /values-ES/strings.xml
, but I suppose that can't be done because the first code should be the language code.
现在,我们将/values-es/strings.xml
文件复制到其他文件夹(values-ca
,values-gl
和values-eu
),但我们希望避免这种情况.
Now we are copying the /values-es/strings.xml
file to the other folders (values-ca
, values-gl
and values-eu
) but we'd like to avoid that.
推荐答案
我认为您应该只具有2个文件夹,每个文件夹具有1个 strings.xml :
I think that you should have only 2 folders with 1 strings.xml for each other:
- res/values/strings.xml 该资源将包含您的文本,以 English ;
- res/values-es/strings.xml .此资源将以西班牙语包含您的文本.
- res/values/strings.xml this resource will contains your text in English ;
- res/values-es/strings.xml this resource will contains your text in Spanish .
当您的应用安装在配置了意大利语语言的设备上时,它将使用案例1中的文件资源.
When your app is installed on a device which is configured with the Italian language, it will use the file resource on case 1.
当您的应用程序安装在配置了 Spanish 语言的设备上(并且有很多 Spanish 语言存在时,请考虑使用 South美国国家/地区),它将在案例2中使用文件资源.
When your app is installed on a device which is configured with a Spanish language (and there are a lot of Spanish language out there, think about South America countries), it will use the file resource on case 2.
您可以使用Android Studio轻松做到这一点:
You can do it easily with Android Studio:
- 右键单击 res 文件夹
- 转到新建">"Android资源目录"
- 一个窗口将为您显示一些选项;选择语言环境,然后单击带有那些符号>>" 的按钮
- 然后在语言列表中,选择 es:西班牙语,然后单击确定",如下图所示(请注意,默认情况下,仅特定区域已选择任何地区!)
- right-click on res folder
- go to New > Android resource directory
- a window will show you some options; pick Locale and then click on the button with those symbols "> >"
- then on the Language list, pick es: Spanish and then click OK, as showed in the image below (note that by default the Specific Region Only has Any Region selected!)
根据经验:我从没遇到过 Breton , Corsican 或Provençal的用户,他们要求以他们的语言完整翻译应用程序(默认情况下,该应用程序默认使用英语和法语.
By experience: I never faced up a Breton, Corsican or Provençal users claiming for a full translation of the application in their language (by default the app has English as default and French).
这篇关于安卓.如何对一个国家/地区的所有语言使用相同的可本地化消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!