Locales class abstract final

Helpers for locales written as strings, such as de_CH.

This package passes locales as strings in the form language[_Script][_REGION][_variant], the form of message file names (messages_zh_Hant_TW.properties). These helpers bring other spellings to that form, list the files a message is looked up in, and hold the platform's default locale. Applications mostly use systemLocale to fix the default locale, for example in tests.

Locales.normalize('ru-ru'); // 'ru_RU'
Locales.normalize('zh-hant-tw'); // 'zh_Hant_TW'
Locales.candidates('de_CH'); // ['de_CH', 'de']
Locales.candidates('zh_Hant_TW'); // ['zh_Hant_TW', 'zh_Hant', 'zh_TW', 'zh']

Spring (Java) uses java.util.Locale objects instead:

Locale locale = Locale.forLanguageTag("zh-Hant-TW"); // zh_TW_#Hant
ResourceBundle.Control.getControl(FORMAT_DEFAULT)
    .getCandidateLocales("messages", locale);

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

systemLocale ↔ String
The default locale of the machine, used when a message is not found in the requested locale.
getter/setter pair

Static Methods

candidates(String locale) → List<String>
The locales whose files are searched for a message of locale, most specific first: ru_RU_x gives [ru_RU_x, ru_RU, ru], zh_Hant_TW gives [zh_Hant_TW, zh_Hant, zh_TW, zh]. The base file (no locale) is not included. Java's ResourceBundle.Control.getCandidateLocales.
normalize(String? locale) → String
Brings locale to the form used in file names: ru-RU and ru_ru become ru_RU, zh-hant-tw (or Java's zh_TW_#Hant) becomes zh_Hant_TW, and null or an empty string gives ''.