Class Language

java.lang.Object
org.faceless.publisher.type.Language
All Implemented Interfaces:
Serializable

public class Language extends Object implements Serializable
Like Locale.Language but useful and fast. Uses no regex, matches can be prioritised, extensions are scored, so "en-x-test" would match in this order:en-x-text, en, en-x-foo
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Language
    The "root" language - all components are empty
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    Return the country, which may be an empty string but never null
    getExtension(char key)
    Return the extension matching the specified letter, or null if no such extension exists
    static Language
    Get a Language that matches the specified text, creating one if necessary
    static Language
    Return a Language that corresponds to the specified Locale
    Return the three-letter language code, which may be an empty string but never null
    Return the two-letter (if available) or three-letter (if not) language code
    Return the Locale that corresponds to this Language tag
    Return the script, which may be an empty string but never null
    Return the first language variants, which may be an empty string but never null
    Return the unmodifiable list of language variants, which may be an empty list
    int
     
    boolean
    Return true if this language has the specified private extension
    int
    Return a score for how well this Language matches the specified Locale, which can be used to determine the best match (higher is better, 0 is no match) This has a strong but not exact relation to BCP47 - once we get to extensions, it differs.
     

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • ROOT

      public static final Language ROOT
      The "root" language - all components are empty
      See Also:
  • Method Details

    • getInstance

      public static Language getInstance(String range)
      Get a Language that matches the specified text, creating one if necessary
      Parameters:
      range - a BCP47 language code
      Returns:
      the Language, or null if its invalid
    • getInstance

      public static Language getInstance(Locale locale)
      Return a Language that corresponds to the specified Locale
      Parameters:
      locale - the locale
      Returns:
      a Language
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hasPrivateExtension

      public boolean hasPrivateExtension(String extn)
      Return true if this language has the specified private extension
      Parameters:
      extn - the extension
    • getLocale

      public Locale getLocale()
      Return the Locale that corresponds to this Language tag
    • getLanguage

      public String getLanguage()
      Return the two-letter (if available) or three-letter (if not) language code
    • getISO3Language

      public String getISO3Language()
      Return the three-letter language code, which may be an empty string but never null
    • getScript

      public String getScript()
      Return the script, which may be an empty string but never null
    • getCountry

      public String getCountry()
      Return the country, which may be an empty string but never null
    • getVariant

      public String getVariant()
      Return the first language variants, which may be an empty string but never null
    • getVariants

      public List<String> getVariants()
      Return the unmodifiable list of language variants, which may be an empty list
    • getExtension

      public String getExtension(char key)
      Return the extension matching the specified letter, or null if no such extension exists
      Parameters:
      key - the extension
    • scoreAgainstPattern

      public int scoreAgainstPattern(Language pattern)
      Return a score for how well this Language matches the specified Locale, which can be used to determine the best match (higher is better, 0 is no match) This has a strong but not exact relation to BCP47 - once we get to extensions, it differs.
      Parameters:
      pattern - the pattern we're matching against. This element should be the "subject" language, the pattern is what we're matching against. For example if this="en-GB-scouse" it will match to "en-GB". But if this is "en-GB" it will NOT match against "en-GB-scouse".
      Returns:
      score the score
    • toString

      public String toString()
      Overrides:
      toString in class Object