Loading...
Searching...
No Matches
localematcher.h File Reference

C++ API: Locale matcher: User's desired locales vs. More...

`#include "unicode/utypes.h"`
`#include <optional>`
`#include "unicode/locid.h"`
`#include "unicode/stringpiece.h"`
`#include "unicode/uobject.h"`

Go to the source code of this file.

## Data Structures

class | icu::LocaleMatcher
| Immutable class that picks the best match between a user's desired locales and an application's supported locales. More...
class | icu::LocaleMatcher::Result
| Data for the best-matching pair of a desired and a supported locale. More...
class | icu::LocaleMatcher::Builder
| LocaleMatcher builder. More...

## Namespaces

namespace | icu
| File coll.h.

## Enumerations

enum | ULocMatchFavorSubtag { ULOCMATCH_FAVOR_LANGUAGE , ULOCMATCH_FAVOR_SCRIPT }
| Builder option for whether the language subtag or the script subtag is most important. More...
enum | ULocMatchDemotion { ULOCMATCH_DEMOTION_NONE , ULOCMATCH_DEMOTION_REGION }
| Builder option for whether all desired locales are treated equally or earlier ones are preferred. More...
enum | ULocMatchDirection { ULOCMATCH_DIRECTION_WITH_ONE_WAY , ULOCMATCH_DIRECTION_ONLY_TWO_WAY }
| Builder option for whether to include or ignore one-way (fallback) match data. More...

## Detailed Description

C++ API: Locale matcher: User's desired locales vs.

application's supported locales.

Definition in file localematcher.h.

## Enumeration Type Documentation

## ULocMatchDemotion

enum ULocMatchDemotion

Builder option for whether all desired locales are treated equally or earlier ones are preferred.

See also
  LocaleMatcher::Builder#setDemotionPerDesiredLocale(ULocMatchDemotion)

Stable
  ICU 65

Enumerator

ULOCMATCH_DEMOTION_NONE

All desired locales are treated equally.

Stable
  ICU 65

ULOCMATCH_DEMOTION_REGION

Earlier desired locales are preferred.

From each desired locale to the next, the distance to any supported locale is increased by an additional amount which is at least as large as most region mismatches. A later desired locale has to have a better match with some supported locale due to more than merely having the same region subtag.

For example: `Supported={en, sv} desired=[en-GB, sv]` yields `Result(en-GB, en)` because with the demotion of sv its perfect match is no better than the region distance between the earlier desired locale en-GB and en=en-US.

Notes:

- In some cases, language and/or script differences can be as small as the typical region difference. (Example: sr-Latn vs. sr-Cyrl)
- It is possible for certain region differences to be larger than usual, and larger than the demotion. (As of CLDR 35 there is no such case, but this is possible in future versions of the data.)

Stable
  ICU 65

Definition at line 57 of file localematcher.h.

## ULocMatchDirection

enum ULocMatchDirection

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.

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 also
  LocaleMatcher::Builder#setDirection(ULocMatchDirection)

Stable
  ICU 67

Enumerator

ULOCMATCH_DIRECTION_WITH_ONE_WAY

Locale matching includes one-way matches such as Breton→French.

(default)

Stable
  ICU 67

ULOCMATCH_DIRECTION_ONLY_TWO_WAY

Locale matching limited to two-way matches including e.g.

Danish↔Norwegian but ignoring one-way matches.

Stable
  ICU 67

Definition at line 113 of file localematcher.h.

## ULocMatchFavorSubtag

enum ULocMatchFavorSubtag

Builder option for whether the language subtag or the script subtag is most important.

See also
  LocaleMatcher::Builder#setFavorSubtag(ULocMatchFavorSubtag)

Stable
  ICU 65

Enumerator

ULOCMATCH_FAVOR_LANGUAGE

Language differences are most important, then script differences, then region differences.

(This is the default behavior.)

Stable
  ICU 65

ULOCMATCH_FAVOR_SCRIPT

Makes script differences matter relatively more than language differences.

Stable
  ICU 65

Definition at line 31 of file localematcher.h.