加拿大的本地化默认为英国;应该默认为美国 [英] Localization for Canada defaults to UK; should default to US

查看:65
本文介绍了加拿大的本地化默认为英国;应该默认为美国的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理的应用程序具有在res/values-en-rGB/strings.xml中指定的英国本地化字符串.对于美国,我的默认字符串实现在res/values/strings.xml中.

I'm working on an application that has localized strings for the UK, specified in res/values-en-rGB/strings.xml. My default string implementations, for the US, are in res/values/strings.xml.

现在,我要在res/values-en-rCA/strings.xml中添加加拿大的其他本地化版本.我希望该应用程序的行为如下:如果用户的设备本地化为加拿大(或他们的语言设置为English(Canada)French(Canada)),请检查我们在,如果没有,则回退到默认的strings.xml文件中的字符串. 但是,当设备设置为加拿大语言环境且在en-rCA中找不到该字符串时,我的应用程序当前会回退到en-rGB中的字符串.因此,我有两个问题:

Now, I'm adding additional localizations for Canada in res/values-en-rCA/strings.xml. I would like the application to behave as follows: If a user's device is localized to Canada (or their language is set to English(Canada) or French(Canada)), check if we have a string in en-rCA, and if not, fallback to the string in my default strings.xml file. However, my application currently fallbacks to strings from en-rGB when the device is set to a Canadian locale and the string is not found in en-rCA. Therefore, I have two questions:

  1. 如何配置我的应用程序,以使具有加拿大语言环境的设备在en-rCA中搜索字符串,然后,如果找不到它,则默认为我的默认values文件夹en-rGB更?

  1. How can I configure my app such that a device with a Canadian locale searches for a string in en-rCA and then, if it cannot find it, defaults to the string in my default values folder rather than en-rGB?

如何确保将语言设置为French (Canada)的设备默认设置为en-rCA而不是当前的默认设置values?

How can I ensure that a device whose language is set to French (Canada) defaults to en-rCA rather than my default values, as it currently does?

如果有帮助,我很乐意提供一个例子.谢谢!

I would be happy to provide an example if it would be helpful. Thanks!

推荐答案

最终更新:

在Google上打开错误报告后, Android N上方的资源解析策略不正确,默认为en_GB而不是默认strings.xml ,他们在上述Android N的预期行为中提到了这一点. en_UK被视为国际英语代表".在使用默认的en字符串之前,这些字符串将退回到国际英语"字符串或其代表.我在这里引用他们的回复:

After opening a bug report on Google Incorrect resource resolution strategy above Android N, defaulting to en_GB and not default strings.xml, they mentioned that this in the intended behaviour for Android N above. en_UK is considered "a representative of International English". The strings will fall back to "International English" strings or its representative before going to default en strings. I'm quoting their reply here:

从N开始,所有英语语言环境(美国和美国领土,如波多黎各和美属萨摩亚除外)都可以使用某些国际英语变体.

Starting in N, all English locales (except for US and US territories like Puerto Rico and American Samoa) fall back to some International English variant if such a locale is available.

因此,对于en-CA,我们将首先尝试这些语言环境,然后再使用en-GB(如果没有更好的国际英语语言环境,则被视为国际英语的代表):en-rCA(加拿大英语), b + en + 001(国际英语),en(英语). 如果您不希望为en-CA选择en-GB字符串,则应将资源放在这三个目录之一中,因为它们被认为是与en-CA更好的匹配.

So for en-CA, we would try these locales first, before falling back on en-GB (which is considered a representative of International English if there is no better International English locale): en-rCA (Canadian English), b+en+001 (International English), en (English). If you don't want en-GB strings to be picked up for en-CA, you should put resources in one of those three directories, as they would be considered a better match for en-CA.


更新1:

似乎这不仅限于en_CA.其他英语语言环境也存在另一个类似的问题: Android 7.0 Nougat在设备语言为en_US 时会选择默认字符串.在这个阶段看起来像是平台错误.

It seems this is not just limited to en_CA. There is another similar question for other English locales : Android 7.0 Nougat picks up default strings when device language is en_US. Looks like a platform bug at this stage.

原始答案:

不确定是错误还是功能.从API级别24(Android 7.0)开始,他们更新了Android如何解析字符串,如所述

Not sure if its a bug or a feature. From API level 24 (Android 7.0), they've updated how Android resolves strings as mentioned Improvements to Resource-Resolution Strategy . Taking an example from the documentation below:

Android 7.0之前的版本:

让我们说一下用户是否具有fr_CH设置,以下是应用程序中可用的资源,即de_DEes_ESfr_FRit_IT.对于Android 7.0之前的较旧API,Android尝试查找完全匹配,如果未找到完全匹配,则默认为values/strings.xml,即en.因此,对于en_CA情况,如果在res/values-en-rCA/strings.xml中找不到字符串,我们可以期望它默认为en.

Lets say if the user has settings of fr_CH and following are the resources available in the app i.e de_DE, es_ES, fr_FR, it_IT. For older API's before Android 7.0, Android tried to find an exact match and if an exact match isn't found it defaults to the values/strings.xml, i.e en. So for en_CA case, if a string is not found in res/values-en-rCA/strings.xml, we can expect it to default to en.

Android 7.0之后

但是,现在在Android 7.0及更高版本中,对于fr_CH的情况,它将回退到最接近的父方言,即fr_FR.

However now in Android 7.0 and above, for the situation of fr_CH, it will fall back to the closest parent dialect i.e fr_FR.

对应用程序中出现的en_CAen_GB的情况应用相同的逻辑,我认为Android认为en_GBen_CA最接近的方言,并且回到它,而不是默认的en首先.我在我的应用程序中遇到了这个问题,这是我只能提出的唯一合理的解释,说明为什么这个问题仅发生在较新的API版本上,而不发生在Android N之前的版本上.

Applying the same logic to the situation of en_CA and en_GB present in the app, I'm thinking that Android thinks that en_GB is the closest dialect to en_CA and is falling back to it instead of the default en first. I am facing the issue in my app and that's the only plausible explanation I can come up with of why this issue happens only on newer API versions and not on the ones before Android N.

这篇关于加拿大的本地化默认为英国;应该默认为美国的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆