Android 7.0 Nougat picks up default strings when device language is en_US

本小妞迷上赌 提交于 2019-12-07 08:46:06

问题


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

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.

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.

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.

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.

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?


回答1:


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:

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.

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.

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.



来源:https://stackoverflow.com/questions/40906548/android-7-0-nougat-picks-up-default-strings-when-device-language-is-en-us

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