public class LocaleMatcher
extends java.lang.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 | Description |
---|---|---|
static class |
LocaleMatcher.LanguageMatcherData |
Deprecated.
This API is ICU internal only.
|
Modifier and Type | Field | Description |
---|---|---|
static boolean |
DEBUG |
Deprecated.
This API is ICU internal only.
|
Constructor | 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(java.lang.String languagePriorityListString) |
Create a new language matcher from a String form.
|
Modifier and Type | Method | Description |
---|---|---|
ULocale |
canonicalize(ULocale ulocale) |
Canonicalize a locale (language).
|
int |
distance(ULocale desired,
ULocale supported) |
Deprecated.
ICU 59: This API is a technical preview.
|
ULocale |
getBestMatch(LocalePriorityList languageList) |
Get the best match for a LanguagePriorityList
|
ULocale |
getBestMatch(ULocale ulocale) |
Get the best match for an individual language code.
|
ULocale |
getBestMatch(ULocale... ulocales) |
Deprecated.
This API is ICU internal only.
|
ULocale |
getBestMatch(java.lang.String languageList) |
Convenience method: Get the best match for a LanguagePriorityList
|
ULocale |
getBestMatch(java.util.LinkedHashSet<ULocale> desiredLanguages,
Output<ULocale> outputBestDesired) |
Deprecated.
ICU 59: This API is a technical preview.
|
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.
|
LocaleMatcher |
setDefaultLanguage(ULocale defaultLanguage) |
Deprecated.
ICU 59: This API is a technical preview.
|
LocaleMatcher |
setFavorScript(boolean favorScript) |
Deprecated.
ICU 59: This API is a technical preview.
|
java.lang.String |
toString() |
@Deprecated public static final boolean DEBUG
public LocaleMatcher(LocalePriorityList languagePriorityList)
languagePriorityList
- weighted listpublic LocaleMatcher(java.lang.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(java.lang.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)
public java.lang.String toString()
toString
in class java.lang.Object
@Deprecated public static com.ibm.icu.impl.ICUResourceBundle getICUSupplementalData()
@Deprecated public static double match(ULocale a, ULocale b)
@Deprecated public int distance(ULocale desired, ULocale supported)
desired
- A locale desired by the usersupported
- A locale supported by a program.@Deprecated public ULocale getBestMatch(java.util.LinkedHashSet<ULocale> desiredLanguages, Output<ULocale> outputBestDesired)
desiredLanguages
- Typically the supplied user's languages, in order of preference, with best first.outputBestDesired
- The one of the desired languages that matched best.
Set to null if the best match was not below the threshold distance.@Deprecated public LocaleMatcher setDefaultLanguage(ULocale defaultLanguage)
defaultLanguage
- Language to use in case the threshold for distance is exceeded.@Deprecated public LocaleMatcher setFavorScript(boolean favorScript)
favorScript
- Set to true to treat script as most important.Copyright ? 2016 Unicode, Inc. and others.