Class XLocaleUtils


  • public final class XLocaleUtils
    extends Object
    Utility class for locale related operations.
    Since:
    8.2.0
    • Method Detail

      • comparingLocaleByDisplayName

        public static Comparator<Locale> comparingLocaleByDisplayName​(Locale locale)
        Compares two locales by their display name in the given locale, ignoring case.
        Parameters:
        locale - The locale to use for obtaining each locale's display name.
        Returns:
        A comparator that compares two locales by their display name in the given locale.
      • getDisplayName

        public static String getDisplayName​(Locale locale,
                                            Locale viewLocale)
        Gets the display name of a locale in the given view locale, or the default display name if the view locale is null.
        Parameters:
        locale - The locale to get the display name of.
        viewLocale - The locale to use for obtaining the display name.
        Returns:
        The display name of the locale.
      • localeBaseLanguage

        public static String localeBaseLanguage​(Locale locale)
        Gets the base language of a locale, returning an empty string if the locale is null.
        Parameters:
        locale - The locale to get the base language of.
        Returns:
        The base language of the locale.
      • toBaseLocale

        public static Locale toBaseLocale​(Locale locale)
        Converts a locale to a base locale, stripping off the country and variant.
        Parameters:
        locale - The locale to convert.
        Returns:
        The base locale.