Package org.omegat.util
Class Language
- java.lang.Object
-
- org.omegat.util.Language
-
- All Implemented Interfaces:
java.lang.Comparable<java.lang.Object>
public class Language extends java.lang.Object implements java.lang.Comparable<java.lang.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 Summary
Constructors Constructor Description Language(java.lang.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.Language(java.util.Locale locale)
Creates a new instance of Language, based on Locale
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(java.lang.Object o)
boolean
equals(java.lang.Object lang)
Indicates whether some other language is "equal to" this one.java.lang.String
getCountryCode()
Returns only a country (YY).java.lang.String
getDisplayName()
Returns a name for the language that is appropriate for display to the user.java.lang.String
getLanguage()
Returns a string representation as an ISO language code (XX-YY).java.lang.String
getLanguageCode()
Returns only a language (XX).static java.util.List<Language>
getLanguages()
Get a list of all languages known to the program.java.util.Locale
getLocale()
returns the Java localejava.lang.String
getLocaleCode()
Returns a string representation as a Java locale (xx_YY).java.lang.String
getLocaleLCID()
Returns a string representation as a Microsoft locale (xx-yy).int
hashCode()
Returns a hash code value for the language.static boolean
isRTL(java.lang.String language)
Check if language is Right-To-Left oriented.boolean
isSameCountryLanguage(java.lang.String target)
boolean
isSameCountryLanguage(Language target)
Returns true if two languages have the same language and country (eg.boolean
isSameLanguage(java.lang.String target)
boolean
isSameLanguage(Language target)
Returns true if two languages have the same language code (eg.boolean
isSpaceDelimited()
Determine whether or not the language is space-delimited.static boolean
localeIsRTL()
Check if locale is Right-To-Left oriented.java.lang.String
toString()
Returns a string representation as an ISO language code (XX-YY).static boolean
verifyLangCode(java.lang.String code)
Verify the correctness of a language or country codestatic boolean
verifySingleLangCode(java.lang.String code)
Verifies whether the language code is OK.
-
-
-
Constructor Detail
-
Language
public Language(java.util.Locale locale)
Creates a new instance of Language, based on Locale
-
Language
public Language(java.lang.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 Detail
-
getDisplayName
public java.lang.String getDisplayName()
Returns a name for the language that is appropriate for display to the user.
-
toString
public java.lang.String toString()
Returns a string representation as an ISO language code (XX-YY).- Overrides:
toString
in classjava.lang.Object
-
getLanguage
public java.lang.String getLanguage()
Returns a string representation as an ISO language code (XX-YY).
-
getLocaleCode
public java.lang.String getLocaleCode()
Returns a string representation as a Java locale (xx_YY).
-
getLocaleLCID
public java.lang.String getLocaleLCID()
Returns a string representation as a Microsoft locale (xx-yy).
-
getLocale
public java.util.Locale getLocale()
returns the Java locale
-
getLanguageCode
public java.lang.String getLanguageCode()
Returns only a language (XX).
-
getCountryCode
public java.lang.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:
- LINGUIST List 6.1302
-
getLanguages
public static java.util.List<Language> getLanguages()
Get a list of all languages known to the program.- Returns:
- Unmodifiable list of languages
-
equals
public boolean equals(java.lang.Object lang)
Indicates whether some other language is "equal to" this one.- Overrides:
equals
in classjava.lang.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 classjava.lang.Object
-
compareTo
public int compareTo(java.lang.Object o)
- Specified by:
compareTo
in interfacejava.lang.Comparable<java.lang.Object>
-
verifyLangCode
public static boolean verifyLangCode(java.lang.String code)
Verify the correctness of a language or country code- Parameters:
code
- A string containing a language or country code- Returns:
true
orfalse
-
verifySingleLangCode
public static boolean verifySingleLangCode(java.lang.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(java.lang.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 thanLanguage.equals()
because of the possible use of BCP47 tags (eg. en-GB-x-ulster / en-GB-x-scotland)
-
isSameCountryLanguage
public boolean isSameCountryLanguage(java.lang.String target)
-
localeIsRTL
public static boolean localeIsRTL()
Check if locale is Right-To-Left oriented.- Returns:
- true if locale is Right-To-Left oriented.
-
isRTL
public static boolean isRTL(java.lang.String language)
Check if language is Right-To-Left oriented.- Parameters:
language
- ISO-639-2 language code- Returns:
- true if language is RTL
-
-