Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.

public class Locale

  1. Object
  2. Locale

A language, a country and a variant, with the JDK’s value semantics: two locales of the same codes are equal, hash alike and print alike (en_US). The codes are normalized as the JDK normalizes them – the language to lower case, the country to upper case, with an ASCII fold, so a device set to Turkish cannot turn IT into a dotless it.

This runtime carries no locale data beyond the English names of the common languages and countries, so the getDisplay* methods answer in English whatever locale they are asked for, and fall back to the code. A script and extensions are not kept: getScript is always empty.

Fields

public static final Locale ENGLISHEnglish.
public static final Locale FRENCHFrench.
public static final Locale GERMANGerman.
public static final Locale ITALIANItalian.
public static final Locale JAPANESEJapanese.
public static final Locale KOREANKorean.
public static final Locale CHINESEChinese.
public static final Locale SIMPLIFIED_CHINESEChinese as written in China.
public static final Locale TRADITIONAL_CHINESEChinese as written in Taiwan.
public static final Locale FRANCEFrench in France.
public static final Locale GERMANYGerman in Germany.
public static final Locale ITALYItalian in Italy.
public static final Locale JAPANJapanese in Japan.
public static final Locale KOREAKorean in Korea.
public static final Locale CHINAChinese in China; the same locale as SIMPLIFIED_CHINESE.
public static final Locale PRCChinese in China; the same locale as SIMPLIFIED_CHINESE.
public static final Locale TAIWANChinese in Taiwan; the same locale as TRADITIONAL_CHINESE.
public static final Locale UKEnglish in the United Kingdom.
public static final Locale USEnglish in the United States.
public static final Locale CANADAEnglish in Canada.
public static final Locale CANADA_FRENCHFrench in Canada.
public static final Locale ROOTThe root locale: no language, country or variant.

Constructors

public Locale(String language)A locale of a language alone.
public Locale(String language, String country)A locale of a language and a country.
public Locale(String language, String country, String variant)A locale of a language, a country and a variant.

Methods

public static Locale of(String language)new Locale(language).
public static Locale of(String language, String country)new Locale(language, country).
public static Locale of(String language, String country, String variant)new Locale(language, country, variant).
public static Locale getDefault()
public static void setDefault(Locale l)
public String getLanguage()
public String getCountry()
public String getVariant()The variant, or the empty string.
public String getScript()Always empty: this runtime does not keep a script.
public boolean hasExtensions()Whether the locale carries extensions; never, here.
public Locale stripExtensions()The locale without extensions, which is the locale itself here.
public static Locale forLanguageTag(String languageTag)The locale an IETF BCP 47 language tag names: fr, en-US, zh-Hans-CN.
public String toLanguageTag()The IETF BCP 47 tag of the locale: en-US, fr, or und for the root.
public boolean equals(Object obj)Whether obj is a locale of the same language, country and variant.
public int hashCode()A hash of the language, country and variant.
public String toString()en_US, fr, en_US_POSIX, or the empty string for the root locale.
public String getDisplayLanguage()The English name of the language, or its code when this runtime has no name for it.
public String getDisplayLanguage(Locale inLocale)As getDisplayLanguage(): names are in English only.
public String getDisplayCountry()The English name of the country, or its code when this runtime has no name for it.
public String getDisplayCountry(Locale inLocale)As getDisplayCountry(): names are in English only.
public String getDisplayVariant()The variant as it is.
public String getDisplayVariant(Locale inLocale)As getDisplayVariant().
public String getDisplayScript()Always empty: this runtime does not keep a script.
public String getDisplayScript(Locale inLocale)Always empty: this runtime does not keep a script.
public String getDisplayName()English (United States): the language, then the country and the variant in parentheses.
public String getDisplayName(Locale inLocale)As getDisplayName(): names are in English only.
public static Locale[] getAvailableLocales()The default locale and the locales this class has constants for.

Inherited methods

Field details

ENGLISH

public static final Locale ENGLISH
English.

FRENCH

public static final Locale FRENCH
French.

GERMAN

public static final Locale GERMAN
German.

ITALIAN

public static final Locale ITALIAN
Italian.

JAPANESE

public static final Locale JAPANESE
Japanese.

KOREAN

public static final Locale KOREAN
Korean.

CHINESE

public static final Locale CHINESE
Chinese.

SIMPLIFIED_CHINESE

public static final Locale SIMPLIFIED_CHINESE
Chinese as written in China.

TRADITIONAL_CHINESE

public static final Locale TRADITIONAL_CHINESE
Chinese as written in Taiwan.

FRANCE

public static final Locale FRANCE
French in France.

GERMANY

public static final Locale GERMANY
German in Germany.

ITALY

public static final Locale ITALY
Italian in Italy.

JAPAN

public static final Locale JAPAN
Japanese in Japan.

KOREA

public static final Locale KOREA
Korean in Korea.

CHINA

public static final Locale CHINA
Chinese in China; the same locale as SIMPLIFIED_CHINESE.

PRC

public static final Locale PRC
Chinese in China; the same locale as SIMPLIFIED_CHINESE.

TAIWAN

public static final Locale TAIWAN
Chinese in Taiwan; the same locale as TRADITIONAL_CHINESE.

UK

public static final Locale UK
English in the United Kingdom.

US

public static final Locale US
English in the United States.

CANADA

public static final Locale CANADA
English in Canada.

CANADA_FRENCH

public static final Locale CANADA_FRENCH
French in Canada.

ROOT

public static final Locale ROOT
The root locale: no language, country or variant.

Constructor details

Locale

public Locale(String language)
A locale of a language alone.

Locale

public Locale(String language, String country)
A locale of a language and a country.

Locale

public Locale(String language, String country, String variant)
A locale of a language, a country and a variant.

Throws

NullPointerException
if any of them is null

Method details

of

public static Locale of(String language)
new Locale(language).

of

public static Locale of(String language, String country)
new Locale(language, country).

of

public static Locale of(String language, String country, String variant)
new Locale(language, country, variant).

getDefault

public static Locale getDefault()

setDefault

public static void setDefault(Locale l)

getLanguage

public String getLanguage()

getCountry

public String getCountry()

getVariant

public String getVariant()
The variant, or the empty string.

getScript

public String getScript()
Always empty: this runtime does not keep a script.

hasExtensions

public boolean hasExtensions()
Whether the locale carries extensions; never, here.

stripExtensions

public Locale stripExtensions()
The locale without extensions, which is the locale itself here.

forLanguageTag

public static Locale forLanguageTag(String languageTag)
The locale an IETF BCP 47 language tag names: fr, en-US, zh-Hans-CN. The first subtag is the language, a four letter subtag after it a script (dropped), the next two letter or three digit subtag the country and the subtags after it, five to eight characters or a digit and three more, the variant. A single character subtag starts the extensions, which are dropped. und and the empty tag are the root locale.

toLanguageTag

public String toLanguageTag()
The IETF BCP 47 tag of the locale: en-US, fr, or und for the root.

equals

public boolean equals(Object obj)
Whether obj is a locale of the same language, country and variant.

hashCode

public int hashCode()
A hash of the language, country and variant.

toString

public String toString()
en_US, fr, en_US_POSIX, or the empty string for the root locale.

getDisplayLanguage

public String getDisplayLanguage()
The English name of the language, or its code when this runtime has no name for it.

getDisplayLanguage

public String getDisplayLanguage(Locale inLocale)
As getDisplayLanguage(): names are in English only.

getDisplayCountry

public String getDisplayCountry()
The English name of the country, or its code when this runtime has no name for it.

getDisplayCountry

public String getDisplayCountry(Locale inLocale)
As getDisplayCountry(): names are in English only.

getDisplayVariant

public String getDisplayVariant()
The variant as it is.

getDisplayVariant

public String getDisplayVariant(Locale inLocale)
As getDisplayVariant().

getDisplayScript

public String getDisplayScript()
Always empty: this runtime does not keep a script.

getDisplayScript

public String getDisplayScript(Locale inLocale)
Always empty: this runtime does not keep a script.

getDisplayName

public String getDisplayName()
English (United States): the language, then the country and the variant in parentheses.

getDisplayName

public String getDisplayName(Locale inLocale)
As getDisplayName(): names are in English only.

getAvailableLocales

public static Locale[] getAvailableLocales()
The default locale and the locales this class has constants for.