Package com.xmlmind.util

## Class LocaleUtil

- java.lang.Object
- - com.xmlmind.util.LocaleUtil

-     public final class LocaleUtil
      extends Object

  A collection of utility functions (static methods) operating on Locales.

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static String` | `getIndividualLanguageCode​(Locale locale)` | Returns the lowercase ISO 639 code corresponding to the individual language of the specified locale.
    `static Locale` | `getLocale​(String lang)` | Returns the Locale corresponding to specified language.
    `static String` | `normalizeLang​(String lang)` | Equivalent to `normalizeLang(lang, null)`.
    `static String` | `normalizeLang​(String lang, String[] parts)` | Returns a normalized, possibly simplified, version of specified language.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### getLocale

          public static Locale getLocale​(String lang)

      Returns the Locale corresponding to specified language.
      Parameters:
        `lang` - specifies the language: a two-letter ISO language code as defined by ISO-639, possibly followed by a two-letter ISO Country Code as defined by ISO-3166. Examples: "en", "en-US", "fr", "fr-CA".
      Returns:
        the Locale corresponding to specified language. Note that this Locale is not necessarily supported by Java methods such as `NumberFormat.getInstance()`.

    - #### normalizeLang

          public static String normalizeLang​(String lang)

      Equivalent to `normalizeLang(lang, null)`.

    - #### normalizeLang

          public static String normalizeLang​(String lang,
                                             String[] parts)

      Returns a normalized, possibly simplified, version of specified language. For example, returns "en-US" (ISO 639-1) for "en_us-win" and "eng" for "ENG" (ISO 639-2 or ISO 639-3).
      Parameters:
        `lang` - a language code preferably matching pattern `[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*`
        `parts` - returns lower_case_language in the first element of this array and upper_case_country or `null` in its second element. May be `null`.
      Returns:
        `lang` normalized as lower_case_language, optionally followed by '-' upper_case_country.

    - #### getIndividualLanguageCode

          public static String getIndividualLanguageCode​(Locale locale)

      Returns the lowercase ISO 639 code corresponding to the individual language of the specified locale.

      For example, returns `nn` for `no-NO-NY` because `no` is just a macrolanguage and not an actual individual language.