设备语言为en_US时,Android 7.0 Nougat会选择默认字符串 [英] Android 7.0 Nougat picks up default strings when device language is en_US

查看:122
本文介绍了设备语言为en_US时,Android 7.0 Nougat会选择默认字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据语言和语言环境中的文档,是对Android 7.0(API级别24)对资源解析策略的改进,可通过下表轻松理解: 改进的资源解析策略

As per the documentation in Language and Locale there have been improvements to Resource-Resolution Strategy from Android 7.0(API level 24) which is easy to understand with the following table: Improved Resource-Resolution strategy

根据我的要求,我希望我的应用的默认语言为en_US.因此,我没有为en_US提供单独的资源.我也有单独提供的en_GB资源.

As per my requirements, I want my app's default langauge to be en_US. So, I am not providing separate resources for en_US. I also have en_GB resources present separately.

现在,根据解决方案策略,如果我的设备的语言为en_US,则它查找资源的顺序为en_US-> en-> en_GB->默认值,这意味着对于en的所有语言环境,在我的情况下为en_GB将会被提取,因为我没有单独的"en"资源,但是存在孩子"en_GB".

Now, as per the resolution strategy, if my device's language is en_US then the order in which it should look for resources is en_US -> en -> en_GB -> default which means for all locales of en, in my case en_GB will be picked up as I don't have 'en' resource separately, but the child 'en_GB' is present.

但是,当我选择设备语言为en_US时,它将正确选择默认语言(在我的情况下为en_US)而不是en_GB,这正是我在设备语言为en_US时所需要的语言.当选择一些其它区域设置像en_IN或EN_AU,它拿起EN_GB.

But, when I select my device language to be en_US, it correctly picks up the default language(en_US in my case) and not en_GB, which is exactly what I need in case the device language is en_US. When some other locale like en_IN or en_AU is selected, it picks up en_GB.

解决此问题的一种方法是,我分别在'en'和en_GB中提供en_US字符串,这将导致我想要的行为.但是,当我选择en_US作为设备语言时,我无法理解为什么要选择默认字符串.

One way to solve this is that I provide en_US strings in 'en' and en_GB separately, which would lead to my desired behaviour. But, I am not able to understand why the default strings are being picked up when I select en_US as my device language.

时认为是EN_US为默认语言机器人和每当EN_US被选择为装置使用的语言,如果EN_US不单独提供它拿起默认字符串?

Is it that en_US is the default language for android and whenever en_US is selected as device's language, it picks up the default strings if en_US is not provided separately?

推荐答案

我遇到了同样的问题.在Google上打开错误报告后, Android N上方的资源解析策略不正确,默认为en_GB而不是默认的strings.xml ,他们在上述Android N的预期行为中提到了这一点.我在这里引用他们的回复:

I was having the same issue. 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. 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.

因此,轮到我们将en_UK视为国际英语的代表".字符串将退回到en之前的国际英语"或其代表.

So, it turns our en_UK is considered "a representative of International English". The strings will fall back to "International English" or its representative before en.

这篇关于设备语言为en_US时,Android 7.0 Nougat会选择默认字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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