Class LocalizationUtil

java.lang.Object
ortus.boxlang.runtime.util.LocalizationUtil

public final class LocalizationUtil extends Object
A Collection of Common Static Properties and Methods to support Localization
  • Field Details

    • COMMON_LOCALES

      public static final LinkedHashMap<Key,Locale> COMMON_LOCALES
      A struct of common locale constants
    • ISO_COUNTRIES

      public static final Array ISO_COUNTRIES
    • ISO_LANGUAGES

      public static final Array ISO_LANGUAGES
    • LOCALE_ALIASES

      public static final HashMap<Key,Locale> LOCALE_ALIASES
      A collection of common locale aliases which are used by both ACF and Lucee
    • COMMON_NUMBER_FORMATTERS

      public static final Struct COMMON_NUMBER_FORMATTERS
      Common Number formatter instances
    • DEFAULT_NUMBER_FORMAT_KEY

      public static final Key DEFAULT_NUMBER_FORMAT_KEY
      Common DateTime formatter instances
    • NUMBER_FORMAT_PATTERNS

      public static final HashMap<Key,String> NUMBER_FORMAT_PATTERNS
      Common number format patterns and shorthand variations
    • CURRENCY_TYPE_LOCAL

      public static final String CURRENCY_TYPE_LOCAL
      See Also:
    • CURRENCY_TYPE_INTERNATIONAL

      public static final String CURRENCY_TYPE_INTERNATIONAL
      See Also:
    • CURRENCY_TYPE_NONE

      public static final String CURRENCY_TYPE_NONE
      See Also:
    • ZONE_ALIASES

      public static final HashMap<Key,String> ZONE_ALIASES
      A struct of ZoneID aliases ( e.g. PST )
  • Constructor Details

    • LocalizationUtil

      public LocalizationUtil()
  • Method Details

    • parseLocale

      public static Locale parseLocale(String requestedLocale)
      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

      public static boolean isAvailableLocale(Locale locale)
      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

      public static String getLocaleDisplayName(Locale locale)
      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

      public static Locale parseLocaleOrDefault(String requestedLocale, Locale defaultLocale)
      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 alias
      defaultLocale - the default locale to use if not found
      Returns:
      The Locale object found or the default
    • parseLocaleFromContext

      public static Locale parseLocaleFromContext(IBoxContext context, ArgumentsScope arguments)
      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 locale
      arguments - The arguments scope which may or may not contain a locale key
      Returns:
      The Locale object found or the default
    • getParsedLocale

      public static Locale getParsedLocale(String locale)
      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

      public static ZoneId parseZoneId(String timezone, IBoxContext context)
      Parses a ZoneId from a string, falling back to the context setting, and then the system default
      Parameters:
      timezone - The timezone string representation
      context - The context to retrieve the config item
      Returns:
      the ZoneId instance representing the assigned timezone
    • parseZoneId

      public static ZoneId parseZoneId(String timezone)
      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

      public static Double parseLocalizedCurrency(Object value, Locale locale)
      Parses a localized currency string
      Parameters:
      value - The value to be parsed
      locale - The locale object to apply to the parse operation
      Returns:
    • parseLocalizedNumber

      public static Double parseLocalizedNumber(Object value, Locale locale)
      Parses a localized number string
      Parameters:
      value - The value to be parsed
      locale - The locale object to apply to the parse operation
      Returns:
      The parsed number or null if the value could not be parsed
    • localizedDateFormatter

      public static DateTimeFormatter localizedDateFormatter(Locale locale, FormatStyle style)
      Returns a localized DateTimeFormatter instance
      Parameters:
      locale - the Locale instance to apply to the formatter
      style - the FormatStyle instance to apply
      Returns:
    • localizedCurrencyFormatter

      public static NumberFormat localizedCurrencyFormatter(Locale locale)
      Returns a localized currency formatter
      Parameters:
      locale - the Locale instance to apply to the formatter
      Returns:
    • localizedCurrencyFormatter

      public static NumberFormat localizedCurrencyFormatter(Locale locale, String type)
      Returns a localized currency formatter
      Parameters:
      locale - the Locale instance to apply to the formatter
      type - A recognized currency format type, which will change or remove the currency symbol
      Returns:
    • localizedDecimalFormatter

      public static DecimalFormat localizedDecimalFormatter(Locale locale)
      Returns a localized decimal formatter
      Parameters:
      locale - the Locale instance to apply to the formatter
      Returns:
    • localizedDecimalFormatter

      public static DecimalFormat localizedDecimalFormatter(Locale locale, String format)
      Returns a localized decimal formatter
      Parameters:
      locale - the Locale instance to apply to the formatter
      Returns:
    • localizedDecimalSymbols

      public static DecimalFormatSymbols localizedDecimalSymbols(Locale locale)
      Returns the localized decimal format symbols for the specified locale
      Parameters:
      locale - the target locale instance
      Returns:
    • getLocaleZonedDateTimeParsers

      public static DateTimeFormatter getLocaleZonedDateTimeParsers(Locale locale)
      Returns a localized set of ZonedDateTime parsers
      Parameters:
      locale - the Locale object which informs the formatters/parsers
      Returns:
      the localized DateTimeFormatter object
    • getLocaleDateTimeParsers

      public static DateTimeFormatter getLocaleDateTimeParsers(Locale locale)
      Returns a localized set of DateTime parsers
      Parameters:
      locale - the Locale object which informs the formatters/parsers
      Returns:
      the localized DateTimeFormatter object
    • getLocaleDateParsers

      public static DateTimeFormatter getLocaleDateParsers(Locale locale)
      Returns a localized set of Date parsers
      Parameters:
      locale - the Locale object which informs the formatters/parsers
      Returns:
      the localized DateTimeFormatter object
    • getLocaleTimeParsers

      public static DateTimeFormatter getLocaleTimeParsers(Locale locale)
      Returns a localized set of Time parsers
      Parameters:
      locale - the Locale object which informs the formatters/parsers
      Returns:
      the localized DateTimeFormatter object
    • buildLocale

      public static Locale buildLocale(String language)
      Convenience method to build a locale from only a language
      Parameters:
      language -
      Returns:
      Locale the locale object
    • buildLocale

      public static Locale buildLocale(String language, String region)
      Convenience method to build a locale from a language and region
      Parameters:
      language -
      region -
      Returns:
      Locale the locale object
    • buildLocale

      public static Locale buildLocale(String language, String region, String variant)
      Convenience method to build a locale from a language, region an variant
      Parameters:
      language -
      region -
      variant -
      Returns:
      Locale the locale object