LocaleMatcherOptions
Options for a LocaleMatcher.
Warning Only use this to disable language tag resolution in cases where your desired tags have the language, script, and region subtags. This is most easily done by passing them through the CLDRFramework.resolveLocale
function, which substitutes subtag aliases and adds likely subtags.
Syntax
{ resolve? }
Properties
resolve?: boolean
- Flag to disable language resolution on the supported language tags. Defaults to
true
. This improves performance when passing in tags that have already been resolved and expanded.
- Flag to disable language resolution on the supported language tags. Defaults to
Example
import { CLDRFramework, LocaleMatcher } from '@phensley/cldr';
const supported = ['en', 'es-419', 'es', 'en-GB', 'pt-BR'].map(
CLDRFramework.resolveLocale
);
let matcher = new LocaleMatcher(supported, { resolve: false });
let { distance, locale } = matcher.match('en-ZA');
log(`${locale.id} distance ${distance}`);
en-GB distance 3
In the case below, resolution is disabled and the supported tags have empty subtags, so the match will fail to calculate correct distances between the supported and supported tags.
matcher = new LocaleMatcher(['en', 'es-419', 'es', 'en-GB', 'pt-BR'], {
resolve: false
});
({ distance, locale } = matcher.match('en-ZA'));
log(`${locale.id} distance ${distance}`);
({ distance, locale } = matcher.match('pt'));
log(`${locale.id} distance ${distance}`);
en distance 100 en distance 100