Closed wafer-li closed 7 years ago
Since the locale of application is set in KcaApplication.java
with preference, so it won't set the locale to English after restart.
But your solution seems to be more clear, I'll merge your commit after checking any dependencies for getLocaleInArray
.
But your solution seems to be more clear, I'll merge your commit after checking any dependencies for getLocaleInArray.
The getLocaleInArray()
only used in MainActivity#setDefaultPreference()
.
That is why I delete that method.
======
Since the locale of application is set in KcaApplication.java with preference, so it won't set the locale to English after restart.
Actually, it will.
As the app first boot, the locale of configuration is the default, let's say, zh-HK
.
And the Preference is set at MainActivity#setDefaultPreference()
.
As there is no zh-HK
locale code.(You use zh-TW
to represent Traditional Chinese at getLocaleCode()
)
It will fallback to en-US
. (It should be set to zh-TW
, but it doesn't).
But, there is the value-zh
fallback resource, so the Android System will use it to display.
Now the Language Preference is en-US
, while the Application use the Traditional Chinese.
That is the problem, you have the wrong language setting "English", but you display the correct language "Traditional Chinese".
But when the app restart, without changing any Preference, which means the Language Preference is still English.
Therefore, it will use the en-US
locale, which will cause the Language to be English.
Oh, I now understand. I haven't notice that problem before. It should be fixed. Thanks for kind explanation!
There is some problems in the current i18n implementation.
Let me explain it:
Background
There is lots of regions in the Chinese language zone, such as CN, HK, TW, MO and SG.
But there are only two main language variants: the Simplified Chinese(简体中文) and the Traditional Chinese(繁體中文).
The CN and SG use Simplified Chinese, and the rest of the regions use Traditional Chinese.
We should use Traditional Chinese as the fallback, because it covers more regions.
As above, we came across the project struct, as I mentioned at https://github.com/antest1/kcanotify/issues/6#issuecomment-286493663:
Problem
There comes the problem, we only have two language variants, and need to deal with a lot of regions.
Now the project using the following code to retrieve the localecode:
And the
languageOptionValue
only provide twozh
value:zh-CN
andzh-TW
What if a user in HK, and the default locale is
zh-HK
, as the structure above, it will fallback tovalue-zh
which provides the Traditional Chinese.But, there is no
zh-HK
inlanguageOptionValue
, then the entry of Language Setting will display the English.And when the user restart the app, it will set the Configuration Locale to English even if we have the correct Localized Resource.
Solution
As This StackOverflow describe, we should set the correct
localecode
in eachstrings.xml
.And retrieve the
localecode
instrings.xml
which is the real currently using language variant.