For IETF BCP 47 language tags you can use the static method Locale.forLanguageTag(String)
. This is available since Android SDK 21. If you want to support lower SDK you can use commons-lang like described here.
In order to comply with IETF BCP 47 the tags must be separated by hyphens (-
). Your first example doesn't work, seems like it should be zh-hans-...
. Your second runs but seems to be wrong, too. I guess it should be either pt-BR
or pt-PT
.
Kindly note that the language tags are case-independent but country codes are usually written in all upper case
Locale chineseSimplifiedHongkong = Locale.forLanguageTag("zh-Hans-HK");
Locale portugueseBrazil = Locale.forLanguageTag("pt-BR");