@formatjs/intl-localematcher 0.10.2 → 0.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +4 -7
- package/index.js +167 -95
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* https://tc39.es/ecma402/#sec-lookupsupportedlocales
|
|
3
|
-
* @param availableLocales
|
|
4
|
-
* @param requestedLocales
|
|
5
|
-
*/
|
|
6
1
|
export declare function LookupSupportedLocales(availableLocales: string[], requestedLocales: string[]): string[];
|
|
7
|
-
|
|
2
|
+
export declare function FilterLocales(availableLocales: Set<string> | readonly string[], requestedLocales: readonly string[], matcher: "lookup" | "best fit", includeHostLocale?: boolean): string[];
|
|
3
|
+
interface ResolveLocaleResult<D = unknown> {
|
|
8
4
|
locale: string;
|
|
9
5
|
dataLocale: string;
|
|
6
|
+
localeData?: D;
|
|
10
7
|
[k: string]: any;
|
|
11
8
|
}
|
|
12
9
|
/**
|
|
@@ -15,7 +12,7 @@ interface ResolveLocaleResult {
|
|
|
15
12
|
export declare function ResolveLocale<K extends string, D extends { [k in K]: any; }>(availableLocales: Set<string> | readonly string[], requestedLocales: readonly string[], options: {
|
|
16
13
|
localeMatcher: string;
|
|
17
14
|
[k: string]: string | null | undefined;
|
|
18
|
-
}, relevantExtensionKeys: K[], localeData: Record<string, D | undefined
|
|
15
|
+
}, relevantExtensionKeys: K[], localeData: Record<string, D | undefined> | undefined, getDefaultLocale: () => string, mode?: "includeLocaleData" | "hostDefaultWithLocaleData" | undefined): ResolveLocaleResult<D>;
|
|
19
16
|
export interface Opts {
|
|
20
17
|
algorithm: "lookup" | "best fit";
|
|
21
18
|
}
|
package/index.js
CHANGED
|
@@ -2,35 +2,39 @@ import { memoize } from "@formatjs/fast-memoize";
|
|
|
2
2
|
// packages/intl-localematcher/abstract/CanonicalizeLocaleList.ts
|
|
3
3
|
let canonicalIntl = globalThis.Intl;
|
|
4
4
|
const getOwnDescriptor = Object.getOwnPropertyDescriptor;
|
|
5
|
-
const apply$
|
|
5
|
+
const apply$3 = Reflect.apply;
|
|
6
|
+
const providerKey = Symbol.for("@formatjs/intlCanonicalizeLocaleList");
|
|
6
7
|
function ownCanonicalizer() {
|
|
7
8
|
const descriptor = canonicalIntl && getOwnDescriptor(canonicalIntl, "getCanonicalLocales");
|
|
8
9
|
return descriptor && getOwnDescriptor(descriptor, "value")?.value;
|
|
9
10
|
}
|
|
10
11
|
let canonicalize$1 = ownCanonicalizer();
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
function registeredCanonicalizer() {
|
|
13
|
+
try {
|
|
14
|
+
const descriptor = canonicalIntl && getOwnDescriptor(canonicalIntl, providerKey);
|
|
15
|
+
return descriptor && getOwnDescriptor(descriptor, "value")?.value;
|
|
16
|
+
} catch {}
|
|
17
|
+
}
|
|
15
18
|
function CanonicalizeLocaleList(locales) {
|
|
16
19
|
if (canonicalIntl === void 0) canonicalIntl = globalThis.Intl;
|
|
17
|
-
const
|
|
18
|
-
if (typeof
|
|
19
|
-
|
|
20
|
+
const registered = registeredCanonicalizer();
|
|
21
|
+
if (typeof registered === "function") return apply$3(registered, canonicalIntl, [locales]);
|
|
22
|
+
if (typeof canonicalize$1 !== "function") canonicalize$1 = ownCanonicalizer();
|
|
23
|
+
return apply$3(canonicalize$1, canonicalIntl, [locales]);
|
|
20
24
|
}
|
|
21
25
|
// packages/intl-localematcher/abstract/intrinsics.ts
|
|
22
|
-
const apply$
|
|
26
|
+
const apply$2 = Reflect.apply;
|
|
23
27
|
const includes = Array.prototype.includes;
|
|
24
28
|
const indexOf = Array.prototype.indexOf;
|
|
25
29
|
function arrayIncludes(values, search) {
|
|
26
|
-
return apply$
|
|
30
|
+
return apply$2(includes, values, [search]);
|
|
27
31
|
}
|
|
28
32
|
function arrayIndexOf(values, search) {
|
|
29
|
-
return apply$
|
|
33
|
+
return apply$2(indexOf, values, [search]);
|
|
30
34
|
}
|
|
31
35
|
const find = Array.prototype.find;
|
|
32
36
|
function arrayFind(values, predicate) {
|
|
33
|
-
return apply$
|
|
37
|
+
return apply$2(find, values, [predicate]);
|
|
34
38
|
}
|
|
35
39
|
const defineProperty = Object.defineProperty;
|
|
36
40
|
function setDataProperty(target, key, value) {
|
|
@@ -47,6 +51,36 @@ const stringIndexOf = Function.prototype.call.bind(String.prototype.indexOf);
|
|
|
47
51
|
const stringLastIndexOf = Function.prototype.call.bind(String.prototype.lastIndexOf);
|
|
48
52
|
const stringLowerCase = Function.prototype.call.bind(String.prototype.toLowerCase);
|
|
49
53
|
const stringCharCodeAt = Function.prototype.call.bind(String.prototype.charCodeAt);
|
|
54
|
+
// packages/intl-localematcher/abstract/BestAvailableLocale.ts
|
|
55
|
+
const LocaleSet$1 = Set;
|
|
56
|
+
const setAdd = Function.prototype.call.bind(Set.prototype.add);
|
|
57
|
+
const setHas = Function.prototype.call.bind(Set.prototype.has);
|
|
58
|
+
const availableLocalesSetCache = /* @__PURE__ */ new WeakMap();
|
|
59
|
+
const getAvailableLocales = availableLocalesSetCache.get.bind(availableLocalesSetCache);
|
|
60
|
+
const setAvailableLocales = availableLocalesSetCache.set.bind(availableLocalesSetCache);
|
|
61
|
+
/**
|
|
62
|
+
* https://tc39.es/ecma402/#sec-lookupmatchinglocalebyprefix
|
|
63
|
+
* @param availableLocales
|
|
64
|
+
* @param locale
|
|
65
|
+
*/
|
|
66
|
+
function BestAvailableLocale(availableLocales, locale) {
|
|
67
|
+
let availableSet = getAvailableLocales(availableLocales);
|
|
68
|
+
if (!availableSet) {
|
|
69
|
+
availableSet = new LocaleSet$1();
|
|
70
|
+
for (let i = 0; i < availableLocales.length; i++) setAdd(availableSet, availableLocales[i]);
|
|
71
|
+
setAvailableLocales(availableLocales, availableSet);
|
|
72
|
+
}
|
|
73
|
+
let candidate = locale;
|
|
74
|
+
while (candidate.length) {
|
|
75
|
+
if (setHas(availableSet, candidate)) return candidate;
|
|
76
|
+
let pos = stringLastIndexOf(candidate, "-");
|
|
77
|
+
if (pos === -1) return;
|
|
78
|
+
while (pos >= 2 && candidate[pos - 2] === "-") pos -= 2;
|
|
79
|
+
candidate = stringSlice(candidate, 0, pos);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// packages/ecma402-abstract/Locale/splitUnicodeExtension.js
|
|
83
|
+
const apply$1 = Reflect.apply;
|
|
50
84
|
const split = String.prototype.split;
|
|
51
85
|
const hyphen = {
|
|
52
86
|
__proto__: null,
|
|
@@ -55,6 +89,28 @@ const hyphen = {
|
|
|
55
89
|
function splitLocaleSubtags(value) {
|
|
56
90
|
return apply$1(split, value, [hyphen]);
|
|
57
91
|
}
|
|
92
|
+
function splitUnicodeExtension(locale) {
|
|
93
|
+
const subtags = splitLocaleSubtags(locale);
|
|
94
|
+
for (let i = 1; i < subtags.length; i++) {
|
|
95
|
+
if (subtags[i] === "x") break;
|
|
96
|
+
if (subtags[i] !== "u") continue;
|
|
97
|
+
let end = i + 1;
|
|
98
|
+
while (end < subtags.length && subtags[end].length > 1) end++;
|
|
99
|
+
let base = subtags[0];
|
|
100
|
+
for (let j = 1; j < i; j++) base += "-" + subtags[j];
|
|
101
|
+
for (let j = end; j < subtags.length; j++) base += "-" + subtags[j];
|
|
102
|
+
let extension = "";
|
|
103
|
+
for (let j = i; j < end; j++) extension += "-" + subtags[j];
|
|
104
|
+
return {
|
|
105
|
+
locale: base,
|
|
106
|
+
extension
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
locale,
|
|
111
|
+
extension: void 0
|
|
112
|
+
};
|
|
113
|
+
}
|
|
58
114
|
// node_modules/.aspect_rules_js/@formatjs_generated+cldr.core@0.0.0/node_modules/@formatjs_generated/cldr.core/matching.js
|
|
59
115
|
const matchingData = {
|
|
60
116
|
"language": {
|
|
@@ -1812,33 +1868,11 @@ const sortLocaleIndexes = Array.prototype.sort;
|
|
|
1812
1868
|
const freezeLocaleList = Object.freeze;
|
|
1813
1869
|
const LocaleError = Error;
|
|
1814
1870
|
const LocaleMap = Map;
|
|
1815
|
-
const LocaleSet
|
|
1816
|
-
const addLocaleSet = Function.prototype.call.bind(LocaleSet
|
|
1817
|
-
const hasLocaleSet = Function.prototype.call.bind(LocaleSet
|
|
1871
|
+
const LocaleSet = Set;
|
|
1872
|
+
const addLocaleSet = Function.prototype.call.bind(LocaleSet.prototype.add);
|
|
1873
|
+
const hasLocaleSet = Function.prototype.call.bind(LocaleSet.prototype.has);
|
|
1818
1874
|
const minDistance = Math.min;
|
|
1819
1875
|
const maxDistance = Math.max;
|
|
1820
|
-
function splitUnicodeExtension(locale) {
|
|
1821
|
-
const subtags = splitLocaleSubtags(locale);
|
|
1822
|
-
for (let i = 1; i < subtags.length; i++) {
|
|
1823
|
-
if (subtags[i] === "x") break;
|
|
1824
|
-
if (subtags[i] !== "u") continue;
|
|
1825
|
-
let end = i + 1;
|
|
1826
|
-
while (end < subtags.length && subtags[end].length > 1) end++;
|
|
1827
|
-
let base = subtags[0];
|
|
1828
|
-
for (let j = 1; j < i; j++) base += "-" + subtags[j];
|
|
1829
|
-
for (let j = end; j < subtags.length; j++) base += "-" + subtags[j];
|
|
1830
|
-
let extension = "";
|
|
1831
|
-
for (let j = i; j < end; j++) extension += "-" + subtags[j];
|
|
1832
|
-
return {
|
|
1833
|
-
locale: base,
|
|
1834
|
-
extension
|
|
1835
|
-
};
|
|
1836
|
-
}
|
|
1837
|
-
return {
|
|
1838
|
-
locale,
|
|
1839
|
-
extension: void 0
|
|
1840
|
-
};
|
|
1841
|
-
}
|
|
1842
1876
|
/**
|
|
1843
1877
|
* Asserts that a condition is true, throwing an error if it is not.
|
|
1844
1878
|
* Used for runtime validation and type narrowing.
|
|
@@ -1860,9 +1894,9 @@ function invariant(condition, message, Err = LocaleError) {
|
|
|
1860
1894
|
const DEFAULT_MATCHING_THRESHOLD = matchingData.defaults[1];
|
|
1861
1895
|
const DISTANCE_SCALE = 8;
|
|
1862
1896
|
const MIN_LSR_DISTANCE = matchingData.minLsrDistance;
|
|
1863
|
-
const languageAliases = new LocaleSet
|
|
1864
|
-
const scriptAliases = new LocaleSet
|
|
1865
|
-
const regionAliases = new LocaleSet
|
|
1897
|
+
const languageAliases = new LocaleSet(matchingData.canonicalAliases.language);
|
|
1898
|
+
const scriptAliases = new LocaleSet(matchingData.canonicalAliases.script);
|
|
1899
|
+
const regionAliases = new LocaleSet(matchingData.canonicalAliases.region);
|
|
1866
1900
|
function ascii(value, start, end, min, max) {
|
|
1867
1901
|
for (let i = start; i < end; i++) {
|
|
1868
1902
|
const code = stringCharCodeAt(value, i);
|
|
@@ -1911,6 +1945,14 @@ function prefix(tag) {
|
|
|
1911
1945
|
end
|
|
1912
1946
|
};
|
|
1913
1947
|
}
|
|
1948
|
+
function scriptlessRegionLocale(tag) {
|
|
1949
|
+
const { language, script, region } = prefix(tag);
|
|
1950
|
+
if (script && region) return language + "-" + region;
|
|
1951
|
+
}
|
|
1952
|
+
function canUseBestFitPrefixFallback(tag) {
|
|
1953
|
+
const { language, script, region } = prefix(tag);
|
|
1954
|
+
return language !== "und" && script !== "Zzzz" && region !== "ZZ" && !pseudoRegion(region) && (stringIndexOf(tag, "-ps") === -1 || fields(tag).pseudo === void 0);
|
|
1955
|
+
}
|
|
1914
1956
|
function fields(tag) {
|
|
1915
1957
|
const parsed = prefix(tag);
|
|
1916
1958
|
const language = parsed.language;
|
|
@@ -1945,7 +1987,7 @@ const canonicalize = memoize((tag) => {
|
|
|
1945
1987
|
if (basic.end === tag.length && languageSubtag(basic.language) && !hasLocaleSet(languageAliases, basic.language) && !hasLocaleSet(scriptAliases, basic.script) && !hasLocaleSet(regionAliases, basic.region)) return tag;
|
|
1946
1988
|
return CanonicalizeLocaleList(tag)[0];
|
|
1947
1989
|
}, { serializer: stringKey });
|
|
1948
|
-
const localeDescriptor = Object.getOwnPropertyDescriptor;
|
|
1990
|
+
const localeDescriptor$1 = Object.getOwnPropertyDescriptor;
|
|
1949
1991
|
const localePrototype = Object.getPrototypeOf;
|
|
1950
1992
|
const LocaleTypeError = TypeError;
|
|
1951
1993
|
const localeOperations = /* @__PURE__ */ new WeakMap();
|
|
@@ -1954,8 +1996,8 @@ const setLocaleOperations = localeOperations.set.bind(localeOperations);
|
|
|
1954
1996
|
let localeIntl = globalThis.Intl;
|
|
1955
1997
|
let localeConstructor;
|
|
1956
1998
|
function localeDescriptorMember(object, key, member = "value") {
|
|
1957
|
-
const descriptor = localeDescriptor(object, key);
|
|
1958
|
-
return descriptor && localeDescriptor(descriptor, member)?.value;
|
|
1999
|
+
const descriptor = localeDescriptor$1(object, key);
|
|
2000
|
+
return descriptor && localeDescriptor$1(descriptor, member)?.value;
|
|
1959
2001
|
}
|
|
1960
2002
|
function localeFieldReader(prototype, key) {
|
|
1961
2003
|
const reader = localeDescriptorMember(prototype, key, "get");
|
|
@@ -2095,9 +2137,10 @@ const immutableLocaleLists = /* @__PURE__ */ new WeakSet();
|
|
|
2095
2137
|
const markLocaleListImmutable = immutableLocaleLists.add.bind(immutableLocaleLists);
|
|
2096
2138
|
const isLocaleListImmutable = immutableLocaleLists.has.bind(immutableLocaleLists);
|
|
2097
2139
|
let paradigms;
|
|
2098
|
-
function createLocaleListSnapshot(locales) {
|
|
2140
|
+
function createLocaleListSnapshot(locales, additionalLocales = []) {
|
|
2099
2141
|
const snapshot = [];
|
|
2100
2142
|
for (let index = 0; index < locales.length; index++) setDataProperty(snapshot, `${index}`, locales[index]);
|
|
2143
|
+
for (let index = 0; index < additionalLocales.length; index++) setDataProperty(snapshot, `${snapshot.length}`, additionalLocales[index]);
|
|
2101
2144
|
markLocaleListImmutable(freezeLocaleList(snapshot));
|
|
2102
2145
|
return snapshot;
|
|
2103
2146
|
}
|
|
@@ -2152,7 +2195,7 @@ function order(data, defaultLocale) {
|
|
|
2152
2195
|
}
|
|
2153
2196
|
}
|
|
2154
2197
|
if (!paradigms) {
|
|
2155
|
-
const keys = new LocaleSet
|
|
2198
|
+
const keys = new LocaleSet();
|
|
2156
2199
|
const tags = matchingData.paradigms;
|
|
2157
2200
|
for (let index = 0; index < tags.length; index++) addLocaleSet(keys, equivalentKey(maximal(canonicalize(tags[index]))));
|
|
2158
2201
|
paradigms = keys;
|
|
@@ -2565,34 +2608,6 @@ function InsertUnicodeExtensionAndCanonicalize(locale, attributes, keywords) {
|
|
|
2565
2608
|
}
|
|
2566
2609
|
return CanonicalizeUnicodeLocaleId(newLocale);
|
|
2567
2610
|
}
|
|
2568
|
-
// packages/intl-localematcher/abstract/BestAvailableLocale.ts
|
|
2569
|
-
const LocaleSet = Set;
|
|
2570
|
-
const setAdd = Function.prototype.call.bind(Set.prototype.add);
|
|
2571
|
-
const setHas = Function.prototype.call.bind(Set.prototype.has);
|
|
2572
|
-
const availableLocalesSetCache = /* @__PURE__ */ new WeakMap();
|
|
2573
|
-
const getAvailableLocales = availableLocalesSetCache.get.bind(availableLocalesSetCache);
|
|
2574
|
-
const setAvailableLocales = availableLocalesSetCache.set.bind(availableLocalesSetCache);
|
|
2575
|
-
/**
|
|
2576
|
-
* https://tc39.es/ecma402/#sec-lookupmatchinglocalebyprefix
|
|
2577
|
-
* @param availableLocales
|
|
2578
|
-
* @param locale
|
|
2579
|
-
*/
|
|
2580
|
-
function BestAvailableLocale(availableLocales, locale) {
|
|
2581
|
-
let availableSet = getAvailableLocales(availableLocales);
|
|
2582
|
-
if (!availableSet) {
|
|
2583
|
-
availableSet = new LocaleSet();
|
|
2584
|
-
for (let i = 0; i < availableLocales.length; i++) setAdd(availableSet, availableLocales[i]);
|
|
2585
|
-
setAvailableLocales(availableLocales, availableSet);
|
|
2586
|
-
}
|
|
2587
|
-
let candidate = locale;
|
|
2588
|
-
while (true) {
|
|
2589
|
-
if (setHas(availableSet, candidate)) return candidate;
|
|
2590
|
-
let pos = stringLastIndexOf(candidate, "-");
|
|
2591
|
-
if (!~pos) return;
|
|
2592
|
-
if (pos >= 2 && candidate[pos - 2] === "-") pos -= 2;
|
|
2593
|
-
candidate = stringSlice(candidate, 0, pos);
|
|
2594
|
-
}
|
|
2595
|
-
}
|
|
2596
2611
|
// packages/intl-localematcher/abstract/LookupMatcher.ts
|
|
2597
2612
|
/**
|
|
2598
2613
|
* https://tc39.es/ecma402/#sec-lookupmatchinglocalebyprefix
|
|
@@ -2664,7 +2679,62 @@ const localeSetValues = Set.prototype.values;
|
|
|
2664
2679
|
const localeSetSize = Object.getOwnPropertyDescriptor(Set.prototype, "size").get;
|
|
2665
2680
|
const localeSetNext = Object.getPrototypeOf((/* @__PURE__ */ new Set()).values()).next;
|
|
2666
2681
|
const localeLowerCase = String.prototype.toLowerCase;
|
|
2667
|
-
|
|
2682
|
+
const localeDescriptor = Object.getOwnPropertyDescriptor;
|
|
2683
|
+
const hostDefaultLocaleKey = Symbol.for("@formatjs/intlHostDefaultLocale");
|
|
2684
|
+
function readHostDefaultLocale() {
|
|
2685
|
+
const intl = localeDescriptorMember(globalThis, "Intl");
|
|
2686
|
+
if (!intl) return void 0;
|
|
2687
|
+
let canRetain = false;
|
|
2688
|
+
try {
|
|
2689
|
+
const retained = localeDescriptor(intl, hostDefaultLocaleKey);
|
|
2690
|
+
const cached = retained && localeDescriptor(retained, "value")?.value;
|
|
2691
|
+
if (typeof cached === "string") return cached;
|
|
2692
|
+
canRetain = retained === void 0;
|
|
2693
|
+
} catch {}
|
|
2694
|
+
for (const name of ["NumberFormat", "DateTimeFormat"]) try {
|
|
2695
|
+
const Constructor = localeDescriptorMember(intl, name);
|
|
2696
|
+
if (typeof Constructor !== "function" || localeDescriptorMember(Constructor, "polyfilled")) continue;
|
|
2697
|
+
const prototype = localeDescriptorMember(Constructor, "prototype");
|
|
2698
|
+
if (!prototype) continue;
|
|
2699
|
+
const resolve = localeDescriptorMember(prototype, "resolvedOptions");
|
|
2700
|
+
if (typeof resolve !== "function") continue;
|
|
2701
|
+
const locale = localeDescriptorMember(localeApply(resolve, new Constructor(), []), "locale");
|
|
2702
|
+
if (typeof locale !== "string" || !locale) continue;
|
|
2703
|
+
const tag = splitUnicodeExtension(locale).locale;
|
|
2704
|
+
try {
|
|
2705
|
+
if (canRetain && Object.isExtensible(intl)) Object.defineProperty(intl, hostDefaultLocaleKey, {
|
|
2706
|
+
__proto__: null,
|
|
2707
|
+
value: tag
|
|
2708
|
+
});
|
|
2709
|
+
} catch {}
|
|
2710
|
+
return tag;
|
|
2711
|
+
} catch {}
|
|
2712
|
+
}
|
|
2713
|
+
const hostDefaultLocale = readHostDefaultLocale();
|
|
2714
|
+
const hostRegionLocale = hostDefaultLocale && scriptlessRegionLocale(hostDefaultLocale);
|
|
2715
|
+
const hostLocaleSupport = /* @__PURE__ */ new WeakMap();
|
|
2716
|
+
const getHostLocaleSupport = hostLocaleSupport.get.bind(hostLocaleSupport);
|
|
2717
|
+
const setHostLocaleSupport = hostLocaleSupport.set.bind(hostLocaleSupport);
|
|
2718
|
+
function getServiceLocaleList(locales, bestFit) {
|
|
2719
|
+
const available = getAvailableLocaleList(locales, bestFit);
|
|
2720
|
+
const cacheable = !localeIsArray(locales);
|
|
2721
|
+
const cached = cacheable && getHostLocaleSupport(available);
|
|
2722
|
+
if (cached) return cached;
|
|
2723
|
+
const dataLocale = hostDefaultLocale && BestAvailableLocale(available, hostDefaultLocale);
|
|
2724
|
+
const aliases = [];
|
|
2725
|
+
if (hostDefaultLocale && dataLocale && dataLocale !== hostDefaultLocale) setDataProperty(aliases, 0, hostDefaultLocale);
|
|
2726
|
+
const regionAlias = dataLocale && hostRegionLocale && arrayIndexOf(available, hostRegionLocale) < 0 ? hostRegionLocale : void 0;
|
|
2727
|
+
if (regionAlias) setDataProperty(aliases, aliases.length, regionAlias);
|
|
2728
|
+
const support = {
|
|
2729
|
+
available: aliases.length ? createLocaleListSnapshot(available, aliases) : available,
|
|
2730
|
+
defaultLocale: dataLocale ? hostDefaultLocale : void 0,
|
|
2731
|
+
dataLocale,
|
|
2732
|
+
regionAlias
|
|
2733
|
+
};
|
|
2734
|
+
if (cacheable) setHostLocaleSupport(available, support);
|
|
2735
|
+
return support;
|
|
2736
|
+
}
|
|
2737
|
+
function getAvailableLocaleList(locales, bestFit) {
|
|
2668
2738
|
if (localeIsArray(locales)) return locales;
|
|
2669
2739
|
const available = locales;
|
|
2670
2740
|
let cached = getLocaleArray(available);
|
|
@@ -2702,20 +2772,25 @@ function localeArray(locales, bestFit) {
|
|
|
2702
2772
|
/**
|
|
2703
2773
|
* https://tc39.es/ecma402/#sec-resolvelocale
|
|
2704
2774
|
*/
|
|
2705
|
-
function ResolveLocale(availableLocales, requestedLocales, options, relevantExtensionKeys, localeData, getDefaultLocale) {
|
|
2775
|
+
function ResolveLocale(availableLocales, requestedLocales, options, relevantExtensionKeys, localeData, getDefaultLocale, mode = void 0) {
|
|
2706
2776
|
const matcher = options.localeMatcher;
|
|
2777
|
+
const hostSupport = mode === "hostDefaultWithLocaleData" ? getServiceLocaleList(availableLocales, matcher !== "lookup") : void 0;
|
|
2778
|
+
const available = hostSupport?.available ?? getAvailableLocaleList(availableLocales, matcher !== "lookup");
|
|
2779
|
+
const hostLocale = hostSupport?.defaultLocale;
|
|
2780
|
+
const defaultLocale = hostLocale ? () => hostLocale : getDefaultLocale;
|
|
2707
2781
|
let r;
|
|
2708
|
-
if (matcher === "lookup") r = LookupMatcher(
|
|
2709
|
-
else r = BestFitMatcher(
|
|
2782
|
+
if (matcher === "lookup") r = LookupMatcher(available, requestedLocales, defaultLocale);
|
|
2783
|
+
else r = BestFitMatcher(available, requestedLocales, defaultLocale);
|
|
2710
2784
|
if (r == null) r = {
|
|
2711
|
-
locale:
|
|
2785
|
+
locale: defaultLocale(),
|
|
2712
2786
|
extension: ""
|
|
2713
2787
|
};
|
|
2714
2788
|
let foundLocale = r.locale;
|
|
2715
|
-
let foundLocaleData = localeData[foundLocale];
|
|
2716
2789
|
const result = { __proto__: null };
|
|
2717
|
-
|
|
2718
|
-
|
|
2790
|
+
const dataLocale = foundLocale === hostLocale || foundLocale === hostSupport?.regionAlias ? hostSupport?.dataLocale ?? foundLocale : foundLocale;
|
|
2791
|
+
const foundLocaleData = localeData?.[dataLocale];
|
|
2792
|
+
result.dataLocale = dataLocale;
|
|
2793
|
+
if (mode) result.localeData = foundLocaleData;
|
|
2719
2794
|
let components;
|
|
2720
2795
|
let keywords;
|
|
2721
2796
|
if (r.extension) {
|
|
@@ -2762,32 +2837,29 @@ function ResolveLocale(availableLocales, requestedLocales, options, relevantExte
|
|
|
2762
2837
|
if (supportedKeyword) setDataProperty(supportedKeywords, `${supportedKeywords.length}`, supportedKeyword);
|
|
2763
2838
|
result[key] = value;
|
|
2764
2839
|
}
|
|
2765
|
-
|
|
2766
|
-
if (supportedKeywords.length > 0) {
|
|
2767
|
-
supportedAttributes = [];
|
|
2768
|
-
foundLocale = InsertUnicodeExtensionAndCanonicalize(foundLocale, supportedAttributes, supportedKeywords);
|
|
2769
|
-
}
|
|
2840
|
+
if (supportedKeywords.length > 0) foundLocale = InsertUnicodeExtensionAndCanonicalize(foundLocale, [], supportedKeywords);
|
|
2770
2841
|
result.locale = foundLocale;
|
|
2771
2842
|
return result;
|
|
2772
2843
|
}
|
|
2773
2844
|
// packages/intl-localematcher/abstract/LookupSupportedLocales.ts
|
|
2774
|
-
/**
|
|
2775
|
-
* https://tc39.es/ecma402/#sec-lookupsupportedlocales
|
|
2776
|
-
* @param availableLocales
|
|
2777
|
-
* @param requestedLocales
|
|
2778
|
-
*/
|
|
2779
2845
|
function LookupSupportedLocales(availableLocales, requestedLocales) {
|
|
2846
|
+
return FilterLocales(availableLocales, requestedLocales, "lookup");
|
|
2847
|
+
}
|
|
2848
|
+
function FilterLocales(availableLocales, requestedLocales, matcher, includeHostLocale = false) {
|
|
2849
|
+
const bestFit = matcher === "best fit";
|
|
2850
|
+
const available = includeHostLocale ? getServiceLocaleList(availableLocales, bestFit).available : getAvailableLocaleList(availableLocales, bestFit);
|
|
2780
2851
|
const subset = [];
|
|
2781
|
-
for (
|
|
2852
|
+
for (let index = 0; index < requestedLocales.length; index++) {
|
|
2853
|
+
const locale = requestedLocales[index];
|
|
2782
2854
|
const { locale: noExtensionLocale } = splitUnicodeExtension(locale);
|
|
2783
|
-
if (BestAvailableLocale(
|
|
2855
|
+
if (matcher === "lookup" ? BestAvailableLocale(available, noExtensionLocale) : findBestMatch([noExtensionLocale], available, void 0, void 0, false).matchedSupportedLocale ?? (canUseBestFitPrefixFallback(noExtensionLocale) ? BestAvailableLocale(available, noExtensionLocale) : void 0)) setDataProperty(subset, subset.length, locale);
|
|
2784
2856
|
}
|
|
2785
2857
|
return subset;
|
|
2786
2858
|
}
|
|
2787
2859
|
// packages/intl-localematcher/index.ts
|
|
2788
2860
|
function match(requestedLocales, availableLocales, defaultLocale, opts) {
|
|
2789
|
-
return ResolveLocale(availableLocales, CanonicalizeLocaleList(requestedLocales), { localeMatcher: opts?.algorithm || "best fit" }, [],
|
|
2861
|
+
return ResolveLocale(availableLocales, CanonicalizeLocaleList(requestedLocales), { localeMatcher: opts?.algorithm || "best fit" }, [], void 0, () => defaultLocale).locale;
|
|
2790
2862
|
}
|
|
2791
|
-
export { LookupSupportedLocales, ResolveLocale, match };
|
|
2863
|
+
export { FilterLocales, LookupSupportedLocales, ResolveLocale, match };
|
|
2792
2864
|
|
|
2793
2865
|
//# sourceMappingURL=index.js.map
|