Package org.faceless.publisher.type
Class Language
java.lang.Object
org.faceless.publisher.type.Language
- All Implemented Interfaces:
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
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Return the country, which may be an empty string but never nullgetExtension
(char key) Return the extension matching the specified letter, or null if no such extension existsstatic Language
getInstance
(String range) Get a Language that matches the specified text, creating one if necessarystatic Language
getInstance
(Locale locale) Return a Language that corresponds to the specified LocaleReturn the three-letter language code, which may be an empty string but never nullReturn the two-letter (if available) or three-letter (if not) language codeReturn the Locale that corresponds to this Language tagReturn the script, which may be an empty string but never nullReturn the first language variants, which may be an empty string but never nullReturn the unmodifiable list of language variants, which may be an empty listint
hashCode()
boolean
hasPrivateExtension
(String extn) Return true if this language has the specified private extensionint
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.toString()
-
Field Details
-
ROOT
The "root" language - all components are empty- See Also:
-
-
Method Details
-
getInstance
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
Return a Language that corresponds to the specified Locale- Parameters:
locale
- the locale- Returns:
- a Language
-
hashCode
public int hashCode() -
equals
-
hasPrivateExtension
Return true if this language has the specified private extension- Parameters:
extn
- the extension
-
getLocale
Return the Locale that corresponds to this Language tag -
getLanguage
Return the two-letter (if available) or three-letter (if not) language code -
getISO3Language
Return the three-letter language code, which may be an empty string but never null -
getScript
Return the script, which may be an empty string but never null -
getCountry
Return the country, which may be an empty string but never null -
getVariant
Return the first language variants, which may be an empty string but never null -
getVariants
Return the unmodifiable list of language variants, which may be an empty list -
getExtension
Return the extension matching the specified letter, or null if no such extension exists- Parameters:
key
- the extension
-
scoreAgainstPattern
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
-