Java Get system language (distinguish between Simplified Chinese and Traditional Chinese)

Source: Internet
Author: User
Tags locale

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]

  1. Locale locale = Locale.getdefault ();

  2. System.out.println (Locale.getlanguage ());

  3. 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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.