Prior to the Android application encountered a problem, that is, depending on the language to display a different content
Many of the online code is wrong, at least can not distinguish between simplified and traditional, here is a method
Does not involve any knowledge of Android, so it is grouped on the Java side.
[Java]
Locale locale = Locale.getdefault ();
System.out.println (Locale.getlanguage ());
System.out.println (Locale.getcountry ());
Here we look at two ways
Public String GetLanguage ()
SINCE:API Level 1
Returns The language code for this Locale or the empty string if no language is set.
Public String Getcountry ()
SINCE:API Level 1
Returns the country code for this locale, or "if this locale is doesn ' t correspond to a specific country.
Return the code, you need to explain the language code and the country code
Language code (or language encoding) is a set of code to represent the language. A language code is a short string of letters or numbers used to classify library collections, the localization of computer programs, and the use of translation. (Transfer from Wikipedia)
Country code (or country codes) is a set of geographic codes used to represent national and foreign territories. A country code is a short string of letters or numbers that is convenient for data processing and communication. There are many different national code standards in the world, the most widely known is ISO 3166-1 for the International Organization for Standardization. The country code may also refer to the international long-distance telephone number, the International Telecommunication Union's International dialling Code (e). (From Wikipedia) (this refers to the former)
So what is the correspondence between the language code and the country code, and we can refer to the following two documents
ISO 639:codes for the representation of names of languages
ISO 3166:codes for the representation of names of countries and their subdivisions
If the system is using Chinese, then the string returned by GetLanguage () is zh, and the result can be judged by getcountry () to be simplified or traditional. If it is TW, then it is traditional, return cn is simplified, if returned to HK, this oneself look to do it ...
In Android, after switching the system language, the return values of the two functions will be changed accordingly.
In Android, Simplified Chinese and Traditional Chinese string resources to be placed under RES/VALUES-ZH-RCN and RES/VALUES-ZH-RTW, why there is a r, I do not know
PS: in ISO 3166-1 alpha-2, the description of TW is: Taiwan, Province of China, or some gratifying
Please keep the following link
My blog Address
http://su1216.iteye.com/
http://blog.csdn.net/su1216/
Java Get system language (distinguish between Simplified Chinese and Traditional Chinese)