Class Language

java.lang.Object
org.omegat.util.Language
All Implemented Interfaces:
Comparable<Object>

public class Language extends Object implements Comparable<Object>
This class is here, because the Locale has hard-coded '_' inside, and we must adhere to ISO standard LL-CC.

This class tries to follow TMX Specification on languages, which is based on RFC 3066, i.e.

  • Language is composed from 1-8 alpha (A-Za-z) chars, then "-", then 1-8 alpha/digit chars (A-Za-z0-9).
  • Case insensitive
  • Case is not altered by this class, even though there exist conventions for capitalization (ISO 3166 recommends that country codes are capitalized (MN Mongolia), and ISO 639 recommends that language codes are written in lower case (mn Mongolian)).
  • Constructor Details

    • Language

      public Language(Locale locale)
      Creates a new instance of Language, based on Locale
    • Language

      public Language(String str)
      Creates a new instance of Language, based on a string of a form "XX_YY" or "XX-YY", where XX is a language code composed from 1-8 alpha (A-Za-z) chars, and YY is a country ISO code composed from 1-8 alpha/digit (A-Za-z0-9) chars.
      The form xx-xxxx-xx is also accepted, where "xxxx" is a 4 alpha characters script as defined in ISO 15924. E.g., sr-Latn-RS, which represents Serbian ('sr') written using Latin script ('Latn') as used in Serbia ('RS'). This form is described in BCP47.
  • Method Details

    • getDisplayName

      public String getDisplayName()
      Returns a name for the language that is appropriate for display to the user.
    • toString

      public String toString()
      Returns a string representation as an ISO language code (XX-YY).
      Overrides:
      toString in class Object
    • getLanguage

      public String getLanguage()
      Returns a string representation as an ISO language code (XX-YY).
    • getLocaleCode

      public String getLocaleCode()
      Returns a string representation as a Java locale (xx_YY).
    • getLocaleLCID

      public String getLocaleLCID()
      Returns a string representation as a Microsoft locale (xx-yy).
    • getLocale

      public Locale getLocale()
      returns the Java locale
    • getLanguageCode

      public String getLanguageCode()
      Returns only a language (XX).
    • getCountryCode

      public String getCountryCode()
      Returns only a country (YY).
    • isSpaceDelimited

      public boolean isSpaceDelimited()
      Determine whether or not the language is space-delimited. Only Chinese, Japanese, and Tibetan are not space-delimited.
      See Also:
    • getLanguages

      public static List<Language> getLanguages()
      Get a list of all languages known to the program.
      Returns:
      Unmodifiable list of languages
    • equals

      public boolean equals(Object lang)
      Indicates whether some other language is "equal to" this one.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Returns a hash code value for the language. Basically returns a hashcode of the underlying Locale object.
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(Object o)
      Specified by:
      compareTo in interface Comparable<Object>
    • verifyLangCode

      public static boolean verifyLangCode(String code)
      Verify the correctness of a language or country code
      Parameters:
      code - A string containing a language or country code
      Returns:
      true or false
    • verifySingleLangCode

      public static boolean verifySingleLangCode(String code)
      Verifies whether the language code is OK.
    • isSameLanguage

      public boolean isSameLanguage(Language target)
      Returns true if two languages have the same language code (eg. fr-FR / fr-CA; es-419/es-BO).
    • isSameLanguage

      public boolean isSameLanguage(String target)
    • isSameCountryLanguage

      public boolean isSameCountryLanguage(Language target)
      Returns true if two languages have the same language and country (eg. fr-FR / fr-FR). Note that it is slightly different than Language.equals() because of the possible use of BCP47 tags (eg. en-GB-x-ulster / en-GB-x-scotland)
    • isSameCountryLanguage

      public boolean isSameCountryLanguage(String target)
    • getLowerCaseLanguageFromLocale

      public static String getLowerCaseLanguageFromLocale()
    • getUpperCaseCountryFromLocale

      public static String getUpperCaseCountryFromLocale()