0

I am new to android development and I am trying to use localized "strings.xml"s.

I created a strings.xml under "res/values-zh". However, my app somehow only use "res/values/strings.xml".

I checked the language using the following code:

Log.d("MainActivity", "default lang = " + Locale.getDefault().language)
Log.d("MainActivity", "resources.configuration.locale.language = " + resources.configuration.locale.language)
Log.d("MainActivity", "resources.configuration.locale = " + resources.configuration.locale)

and the result is:

2019-04-22 21:53:08.182 9431-9431/com.example.myandriod D/MainActivity: default lang = zh
2019-04-22 21:53:08.182 9431-9431/com.example.myandriod D/MainActivity: resources.configuration.locale.language = zh
2019-04-22 21:53:08.182 9431-9431/com.example.myandriod D/MainActivity: resources.configuration.locale = zh_HK_#Hant

What did I do wrong?


Update:

After some more googling, it seems this is a problem only occurs for Chinese. "res/values-zh/strings.xml" no longer works since Andriod 7.0, it must be changed to "res/values-zh-rHK/strings.xml" or "res/values-zh-rTW/strings.xml".

I still don't fully understand why it is so. For those who are interested, see https://gist.github.com/amake/0ac7724681ac1c178c6f95a5b09f03ce#new-locales-vs-old-locales-chinese

san1127
  • 153
  • 2
  • 9

0 Answers0