Locale resolution
Resolution is the process of filling in any undefined subtags, and replacing subtag aliases with a preferred value.
The function CLDRFramework.resolveLocale performs both parsing and resolution, returning a Locale object.
A Locale object has two properties: id
is the original unaltered identifier, and tag
is the LanguageTag object with its subtags resolved and normalized.
The resolution process and the Locale object are important since there are parts of the library which require the value for a specific subtag. For example, pluralization uses the language subtag, and selecting a measurement system (US, UK, Metric) uses the region subtag. The resolution process ensures these subtags are populated.
In the example below, the identifier "und-US"
uses the undefined language subtag, and its script subtag is missing. The resolution process will apply "likely subtags" data to fill in these undefined values.
import { CLDRFramework } from '@phensley/cldr';
let { id, tag } = CLDRFramework.resolveLocale('und-US');
log(id);
log(tag.expanded());
und-US en-Latn-US
In other cases a subtag is aliased to a preferred value that should be used. Resolution will perform language and region alias substitution.
const { id, tag } = CLDRFramework.resolveLocale('cmn-TW');
log(tag.compact());
zh-Hant-TW
Irregular or grandfathered tags are mapped directly to a replacement value.
const { id, tag } = CLDRFramework.resolveLocale('i-klingon');
log(tag.language());
tlh
If all subtags are undefined, as in "und-Zzzz-ZZ"
the library currently resolves this to "en-Latn-US"
. Language resolution alone should not be relied on to perform quasi-language matching or defaulting. See the language matching section for more on this.