Locale fallback
The Lookup API implements automatic language matching and
locale fallback. These mechanisms are available to in-tree uses
that call the C++ function [intl::Lookup::New][iln]
Locale fallback is the process of searching for translated content, locale data, or other resources by "falling back" from more-specific resources to more-general ones following a deterministic pattern.
As a simple example of fallback, a lookup request for a message with the locale
en-US falls back to using a message from the locale en if no
en-US-specific message was available to the system.
Fallbacks are not always straightforward. As a simple example, en-US falls
back to en, but en-IN falls back go en-GB. The fallback
relationships are defined in CLDR, and Fuchsia's localization subsystem
uses this information to select the correct fallback localization.
Fuchsia's localized message lookup has two levels of fallback:
- [Language matching.][langm]
The user is allowed to specify up to 10 preferred locales, in order of
preference. This is supported as part of the type
fuchsia.intl.Profile.
This setting can be handed over to the Lookup API at
Lookup construction time:
This example shows that the user sets a preference to see messages in the
locale es, with a fall back to en-US It is expected that the locale
information will come from fuchsia.intl.Profile normally at runtime.
- Fallback. The lookup library automatically falls back from a more specific locale to a less specific locale even when not explicitly requested by the user. In the prior example:
This example also defines that if en-US is not available, that the locale
should fall back to en. This approach allows us to provide a set of most
general locales for products that may not need worldwide coverage while still
covering the most common locales.
The combination of the two approaches uses the automated rules to find the best available matching locale, but also allows the library caller to specify fine grained sequence of preferred locales to use.
Future work
See Future work section for details on planned but not yet implemented features related to fallback.
iln http://unicode.org/reports/tr35/#LanguageMatching