public class LocaleMatcher extends Object
LocaleMatcher matcher = new LocaleMatcher("fr, en-GB, en"); // afterwards: matcher.getBestMatch("en-US").toLanguageTag() => "en"It takes into account when languages are close to one another, such as fil and tl, and when language regional variants are close, like en-GB and en-AU. It also handles scripts, like zh-Hant vs zh-TW. For examples, see the test file.
All classes implementing this interface should be immutable. Often a product will just need one static instance, built with the languages that it supports. However, it may want multiple instances with different default languages based on additional information, such as the domain.
Modifier and Type | Class and Description |
---|---|
static class |
LocaleMatcher.LanguageMatcherData
Deprecated.
This API is ICU internal only.
|
Constructor and Description |
---|
LocaleMatcher(LocalePriorityList languagePriorityList)
Create a new language matcher.
|
LocaleMatcher(LocalePriorityList languagePriorityList,
LocaleMatcher.LanguageMatcherData matcherData)
Deprecated.
This API is ICU internal only.
|
LocaleMatcher(LocalePriorityList languagePriorityList,
LocaleMatcher.LanguageMatcherData matcherData,
double threshold)
Deprecated.
This API is ICU internal only.
|
LocaleMatcher(String languagePriorityListString)
Create a new language matcher from a String form.
|
Modifier and Type | Method and Description |
---|---|
ULocale |
canonicalize(ULocale ulocale)
Canonicalize a locale (language).
|
ULocale |
getBestMatch(LocalePriorityList languageList)
Get the best match for a LanguagePriorityList
|
ULocale |
getBestMatch(String languageList)
Convenience method: Get the best match for a LanguagePriorityList
|
ULocale |
getBestMatch(ULocale... ulocales)
Deprecated.
This API is ICU internal only.
|
ULocale |
getBestMatch(ULocale ulocale)
Get the best match for an individual language code.
|
static com.ibm.icu.impl.ICUResourceBundle |
getICUSupplementalData()
Deprecated.
This API is ICU internal only.
|
static double |
match(ULocale a,
ULocale b)
Deprecated.
This API is ICU internal only.
|
double |
match(ULocale desired,
ULocale desiredMax,
ULocale supported,
ULocale supportedMax)
Returns a fraction between 0 and 1, where 1 means that the languages are a
perfect match, and 0 means that they are completely different.
|
String |
toString() |
public LocaleMatcher(LocalePriorityList languagePriorityList)
languagePriorityList
- weighted listpublic LocaleMatcher(String languagePriorityListString)
languagePriorityListString
- String form of LanguagePriorityList@Deprecated public LocaleMatcher(LocalePriorityList languagePriorityList, LocaleMatcher.LanguageMatcherData matcherData)
languagePriorityList
- LocalePriorityList to matchmatcherData
- Internal matching data@Deprecated public LocaleMatcher(LocalePriorityList languagePriorityList, LocaleMatcher.LanguageMatcherData matcherData, double threshold)
languagePriorityList
- LocalePriorityList to matchmatcherData
- Internal matching datapublic double match(ULocale desired, ULocale desiredMax, ULocale supported, ULocale supportedMax)
desired
- Desired localedesiredMax
- Maximized locale (using likely subtags)supported
- Supported localesupportedMax
- Maximized locale (using likely subtags)public ULocale canonicalize(ULocale ulocale)
ulocale
- language/locale codepublic ULocale getBestMatch(LocalePriorityList languageList)
languageList
- list to matchpublic ULocale getBestMatch(String languageList)
languageList
- String form of language priority listpublic ULocale getBestMatch(ULocale ulocale)
ulocale
- locale/language code to match@Deprecated public ULocale getBestMatch(ULocale... ulocales)
@Deprecated public static com.ibm.icu.impl.ICUResourceBundle getICUSupplementalData()
@Deprecated public static double match(ULocale a, ULocale b)
Copyright (c) 2014 IBM Corporation and others.