Class LocaleUtility


  • public class LocaleUtility
    extends java.lang.Object
    A class to hold utility functions missing from java.util.Locale.
    • Constructor Summary

      Constructors 
      Constructor Description
      LocaleUtility()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Locale fallback​(java.util.Locale loc)
      Fallback from the given locale name by removing the rightmost _-delimited element.
      static java.util.Locale getLocaleFromName​(java.lang.String name)
      A helper function to convert a string of the form aa_BB_CC to a locale object.
      static boolean isFallbackOf​(java.lang.String parent, java.lang.String child)
      Compare two locale strings of the form aa_BB_CC, and return true if parent is a 'strict' fallback of child, that is, if child =~ "^parent(_.+)*" (roughly).
      static boolean isFallbackOf​(java.util.Locale parent, java.util.Locale child)
      Compare two locales, and return true if the parent is a 'strict' fallback of the child (parent string is a fallback of child string).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LocaleUtility

        public LocaleUtility()
    • Method Detail

      • getLocaleFromName

        public static java.util.Locale getLocaleFromName​(java.lang.String name)
        A helper function to convert a string of the form aa_BB_CC to a locale object. Why isn't this in Locale?
      • isFallbackOf

        public static boolean isFallbackOf​(java.lang.String parent,
                                           java.lang.String child)
        Compare two locale strings of the form aa_BB_CC, and return true if parent is a 'strict' fallback of child, that is, if child =~ "^parent(_.+)*" (roughly).
      • isFallbackOf

        public static boolean isFallbackOf​(java.util.Locale parent,
                                           java.util.Locale child)
        Compare two locales, and return true if the parent is a 'strict' fallback of the child (parent string is a fallback of child string).
      • fallback

        public static java.util.Locale fallback​(java.util.Locale loc)
        Fallback from the given locale name by removing the rightmost _-delimited element. If there is none, return the root locale ("", "", ""). If this is the root locale, return null. NOTE: The string "root" is not recognized; do not use it.
        Returns:
        a new Locale that is a fallback from the given locale, or null.