|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ibm.icu.util.LocaleMatcher
public class LocaleMatcher
Provides a way to match the languages (locales) supported by a product to the languages (locales) acceptable to a user, and get the best match. For example:
LanguageMatcher matcher = new StandardLanguageMatcher("fr, en-GB, en"); // afterwards: matcher.getBestMatch(LanguageCode.US).first == LanguageCode.ENGLISHIt 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.
Nested Class Summary | |
---|---|
static class |
LocaleMatcher.LanguageMatcherData
Deprecated. This API is ICU internal only. |
Constructor Summary | |
---|---|
LocaleMatcher(LocalePriorityList languagePriorityList)
Create a new language matcher. |
|
LocaleMatcher(LocalePriorityList languagePriorityList,
LocaleMatcher.LanguageMatcherData matcherData)
Deprecated. This API is ICU internal only. |
|
LocaleMatcher(java.lang.String languagePriorityListString)
Create a new language matcher from a String form. |
Method Summary | |
---|---|
ULocale |
canonicalize(ULocale ulocale)
Canonicalize a locale (language). |
ULocale |
getBestMatch(LocalePriorityList languageList)
Get the best match for a LanguagePriorityList |
ULocale |
getBestMatch(java.lang.String languageList)
Convenience method: Get the best match for a LanguagePriorityList |
ULocale |
getBestMatch(ULocale ulocale)
Get the best match for an individual language code. |
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. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public LocaleMatcher(LocalePriorityList languagePriorityList)
languagePriorityList
- weighted listpublic LocaleMatcher(java.lang.String languagePriorityListString)
languagePriorityListString
- String form of LanguagePriorityListpublic LocaleMatcher(LocalePriorityList languagePriorityList, LocaleMatcher.LanguageMatcherData matcherData)
languagePriorityList
- LocalePriorityList to matchmatcherData
- Internal matching dataMethod Detail |
---|
public 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 code
public ULocale getBestMatch(LocalePriorityList languageList)
languageList
- list to match
public ULocale getBestMatch(java.lang.String languageList)
languageList
- String form of language priority list
public ULocale getBestMatch(ULocale ulocale)
ulocale
- locale/language code to match
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |