// © 2019 and later: Unicode, Inc. and others. // License & terms of use: http://www.unicode.org/copyright.html // localematcher.h // created: 2019may08 Markus W. Scherer #ifndef __LOCALEMATCHER_H__ #define __LOCALEMATCHER_H__ #include "unicode/utypes.h" #if U_SHOW_CPLUSPLUS_API #include <optional> #include "unicode/locid.h" #include "unicode/stringpiece.h" #include "unicode/uobject.h" /** * \file * \brief C++ API: Locale matcher: User's desired locales vs. application's supported locales. */ /** * Builder option for whether the language subtag or the script subtag is most important. * * @see LocaleMatcher::Builder#setFavorSubtag(ULocMatchFavorSubtag) * @stable ICU 65 */ enum ULocMatchFavorSubtag { … }; #ifndef U_IN_DOXYGEN ULocMatchFavorSubtag; #endif /** * Builder option for whether all desired locales are treated equally or * earlier ones are preferred. * * @see LocaleMatcher::Builder#setDemotionPerDesiredLocale(ULocMatchDemotion) * @stable ICU 65 */ enum ULocMatchDemotion { … }; #ifndef U_IN_DOXYGEN ULocMatchDemotion; #endif /** * Builder option for whether to include or ignore one-way (fallback) match data. * The LocaleMatcher uses CLDR languageMatch data which includes fallback (oneway=true) entries. * Sometimes it is desirable to ignore those. * * <p>For example, consider a web application with the UI in a given language, * with a link to another, related web app. * The link should include the UI language, and the target server may also use * the client’s Accept-Language header data. * The target server has its own list of supported languages. * One may want to favor UI language consistency, that is, * if there is a decent match for the original UI language, we want to use it, * but not if it is merely a fallback. * * @see LocaleMatcher::Builder#setDirection(ULocMatchDirection) * @stable ICU 67 */ enum ULocMatchDirection { … }; #ifndef U_IN_DOXYGEN ULocMatchDirection; #endif struct UHashtable; U_NAMESPACE_BEGIN struct LSR; class LikelySubtags; class LocaleDistance; class LocaleLsrIterator; class UVector; /** * Immutable class that picks the best match between a user's desired locales and * an application's supported locales. * Movable but not copyable. * * <p>Example: * <pre> * UErrorCode errorCode = U_ZERO_ERROR; * LocaleMatcher matcher = LocaleMatcher::Builder().setSupportedLocales("fr, en-GB, en").build(errorCode); * Locale *bestSupported = matcher.getBestLocale(Locale.US, errorCode); // "en" * </pre> * * <p>A matcher takes into account when languages are close to one another, * such as Danish and Norwegian, * and when regional variants are close, like en-GB and en-AU as opposed to en-US. * * <p>If there are multiple supported locales with the same (language, script, region) * likely subtags, then the current implementation returns the first of those locales. * It ignores variant subtags (except for pseudolocale variants) and extensions. * This may change in future versions. * * <p>For example, the current implementation does not distinguish between * de, de-DE, de-Latn, de-1901, de-u-co-phonebk. * * <p>If you prefer one equivalent locale over another, then provide only the preferred one, * or place it earlier in the list of supported locales. * * <p>Otherwise, the order of supported locales may have no effect on the best-match results. * The current implementation compares each desired locale with supported locales * in the following order: * 1. Default locale, if supported; * 2. CLDR "paradigm locales" like en-GB and es-419; * 3. other supported locales. * This may change in future versions. * * <p>Often a product will just need one matcher 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. * * <p>This class is not intended for public subclassing. * * @stable ICU 65 */ class U_COMMON_API LocaleMatcher : public UMemory { … }; U_NAMESPACE_END #endif // U_SHOW_CPLUSPLUS_API #endif // __LOCALEMATCHER_H__