java.lang.Object
com.inductiveautomation.ignition.common.i18n.LocaleUtils

public final class LocaleUtils extends Object
Utility methods for working with Locale objects, including sorting and parsing.
  • Field Details

    • LOCALE_COMPARATOR

      public static final Comparator<Locale> LOCALE_COMPARATOR
      A comparator that sorts Locales by display language, then by display country, case-insensitively.
  • Method Details

    • getAvailableLocales

      public static List<Locale> getAvailableLocales(boolean andRegionalVariants)
      Returns the available locales, sorted.
      Parameters:
      andRegionalVariants - If true, regional variants (e.g., en_US) are included. If false, only base languages (e.g., en) are returned.
      Returns:
      A sorted list of available locales.
    • parseLocale

      public static Optional<Locale> parseLocale(@Nullable String locale)
      Attempt to parse the given string into a locale - first, as a Java formatted locale, using LocaleUtils.toLocale(String) - but if that fails, then by parsing it as a language tag. Will attempt to return an empty optional, rather than an invalid locale.
      Parameters:
      locale - The locale string to parse. Can be Java-style (en_US) or a language tag (en-US).
      Returns:
      An Optional containing the parsed Locale, or empty if parsing fails.