Class LocaleInfo
- All Implemented Interfaces:
Cloneable
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final LocaleInfoThe system default locale info.static final LocaleInfoThe Locale.ENGLISH based locale info.Method Summary
Modifier and TypeMethodDescriptionclone()Clones the instance.Gets a Currency NumberFormat in the specified locale with the currency symbols loaded.Gets a default DecimalFormat instance that can be used by cloning to set patterns, etc.Gets an Integer NumberFormat in the specified locale.Gets the NumberFormat.Gets a Percent NumberFormat in the specified locale.formatTemperature(double temperature, int decimals, TemperatureUnit unit) Converts a temperature to a String.formatTemperature(float temperature, int decimals, TemperatureUnit unit) Converts a temperature to a String.Gets the collator used for sorting strings for this locale.Gets the currency instance.static LocaleInfogetCurrent(boolean logDefault) Gets the current LocalInfo for the calling thread.getDateTimeFormatter(String pattern) Gets the date and time formatter in this locale of the specified pattern.getDateTimeFormatter(FormatStyle style) Gets the date and time formatter in this locale of the specified type.Gets the DecimalFormatSymbols object for the locale.Gets the language code to use.Gets the locale.static LocaleInfogetLocaleInfo(String languageCode) Creates or gets a cached copy of a locale for a language code.static LocaleInfogetLocaleInfo(String country, String language, String variant) Creates or gets a cached copy of a locale for a language.static LocaleInfogetLocaleInfo(Locale locale) Creates or gets a cached copy of a locale for a language.static LocaleInfogetNonNull(LocaleInfo localeInfo, boolean logDefault) Returns the LocaleInfo from the parameter if non-null, otherwise takes the current user's LocaleInfo or the system's.org.joda.time.format.PeriodFormatterGets the period formatter in this locale.Gets the time-zone.Gets the time-zone ID.Gets the time-zone offset.intinitializeTimeZone(int offset, String name) Initializes the time-zone information.booleanReturns if the locale is using Default English.static voidsetCurrent(LocaleInfo localeInfo) Sets the current LocaleInfo, i.e.
Field Details
ENGLISH_LOCALEINFO
The Locale.ENGLISH based locale info.DEFAULT_LOCALEINFO
The system default locale info.
Method Details
getLocaleInfo
Creates or gets a cached copy of a locale for a language code.- Parameters:
languageCode- The IETF BCP 47 language tag, e.g. "en-US". The tag is canonicalized, so "en-us" and "en-US" share one cached instance. A tag that is not well-formed, e.g. "en_US" with an underscore, yields the root locale and is logged as a warning.- Returns:
- The LocaleInfo for the parameters.
- Throws:
NullPointerException- IflanguageCodeisnull.
getLocaleInfo
Creates or gets a cached copy of a locale for a language.- Parameters:
locale- The locale, non-null.- Returns:
- A cloned LocaleInfo from a cached instance for the locale in question.
- Throws:
NullPointerException- Iflocaleisnull.
getLocaleInfo
Creates or gets a cached copy of a locale for a language.- Parameters:
country- The country, an ISO 3166 two-letter code, null for the country of the default locale. Anything else, e.g. a three-letter code, is treated as no country.language- The language, null for none.variant- The variant, null for none.- Returns:
- The LocaleInfo for the parameters. If all parameters are
null, or none of them names anything, a CLONE of the current LocaleInfo is returned - never the shared instance itself, whichinitializeTimeZone(int,String)refuses to be called on.
setCurrent
Sets the current LocaleInfo, i.e. for the Designer. This method throws IllegalStateException if executing elsewhere that in the Designer.- Parameters:
localeInfo- The default locale information.- Throws:
IllegalStateException- When called and the Designer is not the calling process.
getNonNull
Returns the LocaleInfo from the parameter if non-null, otherwise takes the current user's LocaleInfo or the system's.- Parameters:
localeInfo- The locale information, or null.logDefault- Flag indicating a warning message is logged if the default is used due to none other LocaleInfo found.- Returns:
- The
localeInfoparameter is non-null, otherwise the user's or system locale information.
getCurrent
Gets the current LocalInfo for the calling thread. This value is extracted from the Thread context depending on where it is executing (i.e. Server, Designer, etc). If none is found, the default LocaleInfo is returned.- Parameters:
logDefault- Flag indicating a warning message is logged if the default is used due to none other LocaleInfo found.- Returns:
- A LocaleInfo instance.
clone
Clones the instance.getLocale
getCollator
Gets the collator used for sorting strings for this locale.- Returns:
- The collator.
isDefaultEnglish
public boolean isDefaultEnglish()Returns if the locale is using Default English.- Returns:
- true if language is English.
getLanguageCode
Gets the language code to use.- Returns:
- The language code, or null for default (not defined by the client).
getCurrency
createNumberFormat
Gets the NumberFormat.- Returns:
- The NumberFormat for the locale.
getDecimalFormatSymbols
Gets the DecimalFormatSymbols object for the locale.- Returns:
- The decimal format symbols the current locale.
createDecimalFormat
Gets a default DecimalFormat instance that can be used by cloning to set patterns, etc. The format returned is a cloned cached copy.- Returns:
- The DecimalFormat instance initialized with the current locale's DecimalFormatSymbols.
createIntegerFormat
Gets an Integer NumberFormat in the specified locale. The format returned is a cloned cached copy.- Returns:
- The Integer NumberFormat instance.
createPercentFormat
Gets a Percent NumberFormat in the specified locale. The format returned is a cloned cached copy.- Returns:
- The Percent NumberFormat instance.
createCurrencyFormat
Gets a Currency NumberFormat in the specified locale with the currency symbols loaded. The format returned is a cloned cached copy.- Returns:
- The Currency NumberFormat instance.
getDateTimeFormatter
Gets the date and time formatter in this locale of the specified type.- Parameters:
style- The format style.- Returns:
- A cached formatter.
- See Also:
getDateTimeFormatter
Gets the date and time formatter in this locale of the specified pattern.- Parameters:
pattern- The pattern.- Returns:
- A formatter.
- See Also:
getPeriodFormatter
public org.joda.time.format.PeriodFormatter getPeriodFormatter()Gets the period formatter in this locale.- Returns:
- The Joda PeriodFormatter instance for the locale.
initializeTimeZone
Initializes the time-zone information. This method is not intended to be called, it is done by the framework.The time-zone offset is EAST-POSITIVE, in minutes: a client at UTC+02:00 sends 120, matching
ZoneOffset. The browser primitive is the other way round -Date.prototype.getTimezoneOffset()is positive WEST - soclient.jsnegates it before sending, inbuildEnv. Do not "simplify" either side: the two conventions disagreeing across the wire was IIZI-JS-ZONEOFFSET-SIGN-INVERTED, which stored the wrong sign for every session from the first release until 2026-08-26.When no usable name arrives, the zone is built from the offset as
ZoneId.ofOffset("GMT",zo)- idGMT+02:00, andGMTat zero offset. That spelling is RFC-adjacent and is what already-persisted values carry, so it is kept DELIBERATELY. Using theZoneOffsetitself (ids+02:00, andZat zero) was considered and REJECTED: a value built by that code would notequals()one parsed from the old persisted string form for the same instant, and the compat break buys nothing the platform needs. See ruling R-B in RULINGS-BATCH2. Do not "modernise" this to the offset or to a "UTC" prefix.- Parameters:
offset- In minutes, -1080 to 1080 inclusive, which is the 18 hours either way thatZoneOffsetpermits. Anything outside is refused with -1 and a warning.name- The time-zone name in the form "{area}/{city}", e.g. "Europe/Berlin", null or empty for none.- Returns:
- -1 for invalid offset, 0=success, 1 for unknown zone name but success. Any problems with offset or name are logged as warnings, including an offset that contradicts a name that did resolve.
- Throws:
IllegalStateException- If called onDEFAULT_LOCALEINFOorENGLISH_LOCALEINFO. Those two are shared by the whole JVM and carry no session; a zone stored on either would be answered to every caller that has none of its own. Clone first - every door of this class hands out clones.
getTimeZone
Gets the time-zone.- Returns:
- The time-zone, if not initialized, the default system time-zone is returned and remembered by this instance.
getZoneId
Gets the time-zone ID.- Returns:
- The time-zone ID, if not initialized, the default system time-zone ID is returned and remembered by this instance.
getZoneOffset
Gets the time-zone offset.When the offset was not initialized, it is the offset
getZoneId()has at this instant, derived from the zone rules and not remembered: a locale that was never given a zone therefore follows the daylight-saving changes of the system time-zone instead of pinning the offset of the day it was first read.- Returns:
- The time-zone offset, if not initialized, the current offset of the default system time-zone is returned.
formatTemperature
Converts a temperature to a String.- Parameters:
temperature- The temperature value.decimals- The number of decimals, zero or more; a negative count is taken as zero.unit- The temperature unit.- Returns:
- The String formatted as e.g. "1234,45 °F" for Fahrenheit, always carrying the locale's separators and the unit suffix, at zero decimals too.
formatTemperature
Converts a temperature to a String.- Parameters:
temperature- The temperature value.decimals- The number of decimals, zero or more; a negative count is taken as zero.unit- The temperature unit.- Returns:
- The String formatted as e.g. "1234,45 °F" for Fahrenheit, always carrying the locale's separators and the unit suffix, at zero decimals too.