Package ortus.boxlang.runtime.util
Class LocalizationUtil
java.lang.Object
ortus.boxlang.runtime.util.LocalizationUtil
A Collection of Common Static Properties and Methods to support Localization
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final LinkedHashMap<Key, Locale> A struct of common locale constantsstatic final StructCommon Number formatter instancesstatic final Stringstatic final Stringstatic final Stringstatic final KeyCommon DateTime formatter instancesstatic final Arraystatic final ArrayA collection of common locale aliases which are used by both ACF and LuceeCommon number format patterns and shorthand variationsA struct of ZoneID aliases ( e.g. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic LocalebuildLocale(String language) Convenience method to build a locale from only a languagestatic LocalebuildLocale(String language, String region) Convenience method to build a locale from a language and regionstatic LocalebuildLocale(String language, String region, String variant) Convenience method to build a locale from a language, region an variantstatic DateTimeFormattergetLocaleDateParsers(Locale locale) Returns a localized set of Date parsersstatic DateTimeFormattergetLocaleDateTimeParsers(Locale locale) Returns a localized set of DateTime parsersstatic StringgetLocaleDisplayName(Locale locale) Get a human-friendly display name for a localestatic DateTimeFormattergetLocaleTimeParsers(Locale locale) Returns a localized set of Time parsersstatic DateTimeFormattergetLocaleZonedDateTimeParsers(Locale locale) Returns a localized set of ZonedDateTime parsersstatic LocalegetParsedLocale(String locale) Parses a locale from a stringstatic booleanisAvailableLocale(Locale locale) Checks if a locale is available for the current JVMstatic NumberFormatlocalizedCurrencyFormatter(Locale locale) Returns a localized currency formatterstatic NumberFormatlocalizedCurrencyFormatter(Locale locale, String type) Returns a localized currency formatterstatic DateTimeFormatterlocalizedDateFormatter(Locale locale, FormatStyle style) Returns a localized DateTimeFormatter instancestatic DecimalFormatlocalizedDecimalFormatter(Locale locale) Returns a localized decimal formatterstatic DecimalFormatlocalizedDecimalFormatter(Locale locale, String format) Returns a localized decimal formatterstatic DecimalFormatSymbolslocalizedDecimalSymbols(Locale locale) Returns the localized decimal format symbols for the specified localestatic LocaleparseLocale(String requestedLocale) Parses a locale from a string, handling known common locales and aliases.static LocaleparseLocaleFromContext(IBoxContext context, ArgumentsScope arguments) Convience method to extract the locale from arguments or context, falling back tothe system defaultstatic LocaleparseLocaleOrDefault(String requestedLocale, Locale defaultLocale) Parses a locale and returns a default value if the locale could not be parsedstatic DoubleparseLocalizedCurrency(Object value, Locale locale) Parses a localized currency stringstatic DoubleparseLocalizedNumber(Object value, Locale locale) Parses a localized number stringstatic ZoneIdparseZoneId(String timezone) Attempts to parse a ZoneId from a string representation - return a null if the zone could not be parsedstatic ZoneIdparseZoneId(String timezone, IBoxContext context) Parses a ZoneId from a string, falling back to the context setting, and then the system default
-
Field Details
-
COMMON_LOCALES
A struct of common locale constants -
ISO_COUNTRIES
-
ISO_LANGUAGES
-
LOCALE_ALIASES
A collection of common locale aliases which are used by both ACF and Lucee -
COMMON_NUMBER_FORMATTERS
Common Number formatter instances -
DEFAULT_NUMBER_FORMAT_KEY
Common DateTime formatter instances -
NUMBER_FORMAT_PATTERNS
Common number format patterns and shorthand variations -
CURRENCY_TYPE_LOCAL
- See Also:
-
CURRENCY_TYPE_INTERNATIONAL
- See Also:
-
CURRENCY_TYPE_NONE
- See Also:
-
ZONE_ALIASES
A struct of ZoneID aliases ( e.g. PST )
-
-
Constructor Details
-
LocalizationUtil
public LocalizationUtil()
-
-
Method Details
-
parseLocale
Parses a locale from a string, handling known common locales and aliases.- Parameters:
requestedLocale- The string representation of the requested locale or alias- Returns:
- the Locale object or null if the locale could not be parsed or found in the current JVM
-
isAvailableLocale
Checks if a locale is available for the current JVM- Parameters:
locale- The locale to check- Returns:
- true if the locale is valid, false otherwise
-
getLocaleDisplayName
Get a human-friendly display name for a locale- Parameters:
locale- The locale to display- Returns:
- The display name in the format `Language (Country)` or `Language (Variant)` if no country is present
-
parseLocaleOrDefault
Parses a locale and returns a default value if the locale could not be parsed- Parameters:
requestedLocale- the string representation of the requested locale or aliasdefaultLocale- the default locale to use if not found- Returns:
- The Locale object found or the default
-
parseLocaleFromContext
Convience method to extract the locale from arguments or context, falling back tothe system default- Parameters:
context- The context from which to extract the default localearguments- The arguments scope which may or may not contain a locale key- Returns:
- The Locale object found or the default
-
getParsedLocale
Parses a locale from a string- Parameters:
locale- The string representation of the locale- Returns:
- The Locale object or null if the locale could not be parsed
-
parseZoneId
Parses a ZoneId from a string, falling back to the context setting, and then the system default- Parameters:
timezone- The timezone string representationcontext- The context to retrieve the config item- Returns:
- the ZoneId instance representing the assigned timezone
-
parseZoneId
Attempts to parse a ZoneId from a string representation - return a null if the zone could not be parsed- Parameters:
timezone- The string representation of the timezone- Returns:
- The ZoneId or null
-
parseLocalizedCurrency
Parses a localized currency string- Parameters:
value- The value to be parsedlocale- The locale object to apply to the parse operation- Returns:
-
parseLocalizedNumber
Parses a localized number string- Parameters:
value- The value to be parsedlocale- The locale object to apply to the parse operation- Returns:
- The parsed number or null if the value could not be parsed
-
localizedDateFormatter
Returns a localized DateTimeFormatter instance- Parameters:
locale- the Locale instance to apply to the formatterstyle- the FormatStyle instance to apply- Returns:
-
localizedCurrencyFormatter
Returns a localized currency formatter- Parameters:
locale- the Locale instance to apply to the formatter- Returns:
-
localizedCurrencyFormatter
Returns a localized currency formatter- Parameters:
locale- the Locale instance to apply to the formattertype- A recognized currency format type, which will change or remove the currency symbol- Returns:
-
localizedDecimalFormatter
Returns a localized decimal formatter- Parameters:
locale- the Locale instance to apply to the formatter- Returns:
-
localizedDecimalFormatter
Returns a localized decimal formatter- Parameters:
locale- the Locale instance to apply to the formatter- Returns:
-
localizedDecimalSymbols
Returns the localized decimal format symbols for the specified locale- Parameters:
locale- the target locale instance- Returns:
-
getLocaleZonedDateTimeParsers
Returns a localized set of ZonedDateTime parsers- Parameters:
locale- the Locale object which informs the formatters/parsers- Returns:
- the localized DateTimeFormatter object
-
getLocaleDateTimeParsers
Returns a localized set of DateTime parsers- Parameters:
locale- the Locale object which informs the formatters/parsers- Returns:
- the localized DateTimeFormatter object
-
getLocaleDateParsers
Returns a localized set of Date parsers- Parameters:
locale- the Locale object which informs the formatters/parsers- Returns:
- the localized DateTimeFormatter object
-
getLocaleTimeParsers
Returns a localized set of Time parsers- Parameters:
locale- the Locale object which informs the formatters/parsers- Returns:
- the localized DateTimeFormatter object
-
buildLocale
Convenience method to build a locale from only a language- Parameters:
language-- Returns:
- Locale the locale object
-
buildLocale
Convenience method to build a locale from a language and region- Parameters:
language-region-- Returns:
- Locale the locale object
-
buildLocale
Convenience method to build a locale from a language, region an variant- Parameters:
language-region-variant-- Returns:
- Locale the locale object
-