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_xgives[ru_RU_x, ru_RU, ru],zh_Hant_TWgives[zh_Hant_TW, zh_Hant, zh_TW, zh]. The base file (no locale) is not included. Java'sResourceBundle.Control.getCandidateLocales. -
normalize(
String? locale) → String -
Brings
localeto the form used in file names:ru-RUandru_rubecomeru_RU,zh-hant-tw(or Java'szh_TW_#Hant) becomeszh_Hant_TW, andnullor an empty string gives''.