1- /* eslint no-magic-numbers: 0 */
2-
31import { Locale } from "./locale.js" ;
42
53/**
@@ -9,68 +7,68 @@ import { Locale } from "./locale.js";
97 * The algorithm is based on the BCP4647 3.3.2 Extended Filtering algorithm,
108 * with several modifications:
119 *
12- * 1) available locales are treated as ranges
10+ * ### 1. Available locales are treated as ranges
1311 *
14- * This change allows us to match a more specific request against
15- * more generic available locale.
12+ * This change allows us to match a more specific request against
13+ * more generic available locale.
1614 *
17- * For example, if the available locale list provides locale `en`,
18- * and the requested locale is `en-US`, we treat the available locale as
19- * a locale that matches all possible english requests.
15+ * For example, if the available locale list provides locale `en`,
16+ * and the requested locale is `en-US`, we treat the available locale as
17+ * a locale that matches all possible english requests.
2018 *
21- * This means that we expect available locale ID to be as precize as
22- * the matches they want to cover.
19+ * This means that we expect available locale ID to be as precize as
20+ * the matches they want to cover.
2321 *
24- * For example, if there is only `sr` available, it's ok to list
25- * it in available locales. But once the available locales has both,
26- * Cyrl and Latn variants, the locale IDs should be `sr-Cyrl` and `sr-Latn`
27- * to avoid any `sr-*` request to match against whole `sr` range.
22+ * For example, if there is only `sr` available, it's ok to list
23+ * it in available locales. But once the available locales has both,
24+ * Cyrl and Latn variants, the locale IDs should be `sr-Cyrl` and `sr-Latn`
25+ * to avoid any `sr-*` request to match against whole `sr` range.
2826 *
29- * What it does ([requested] * [available] = [supported]):
27+ * What it does ([requested] * [available] = [supported]):
3028 *
31- * ['en-US'] * ['en'] = ['en']
29+ * ['en-US'] * ['en'] = ['en']
3230 *
33- * 2) likely subtags from LDML 4.3 Likely Subtags has been added
31+ * ### 2. Likely subtags from LDML 4.3 Likely Subtags has been added
3432 *
35- * The most obvious likely subtag that can be computed is a duplication
36- * of the language field onto region field (`fr` => `fr-FR`).
33+ * The most obvious likely subtag that can be computed is a duplication
34+ * of the language field onto region field (`fr` => `fr-FR`).
3735 *
38- * On top of that, likely subtags may use a list of mappings, that
39- * allow the algorithm to handle non-obvious matches.
40- * For example, making sure that we match `en` to `en-US` or `sr` to
41- * `sr-Cyrl`, while `sr-RU` to `sr-Latn-RU`.
36+ * On top of that, likely subtags may use a list of mappings, that
37+ * allow the algorithm to handle non-obvious matches.
38+ * For example, making sure that we match `en` to `en-US` or `sr` to
39+ * `sr-Cyrl`, while `sr-RU` to `sr-Latn-RU`.
4240 *
43- * This list can be taken directly from CLDR Supplemental Data.
41+ * This list can be taken directly from CLDR Supplemental Data.
4442 *
45- * What it does ([requested] * [available] = [supported]):
43+ * What it does ([requested] * [available] = [supported]):
4644 *
47- * ['fr'] * ['fr-FR'] = ['fr-FR']
48- * ['en'] * ['en-US'] = ['en-US']
49- * ['sr'] * ['sr-Latn', 'sr-Cyrl'] = ['sr-Cyrl']
45+ * ['fr'] * ['fr-FR'] = ['fr-FR']
46+ * ['en'] * ['en-US'] = ['en-US']
47+ * ['sr'] * ['sr-Latn', 'sr-Cyrl'] = ['sr-Cyrl']
5048 *
51- * 3) variant /region range check has been added
49+ * ### 3. Variant /region range check has been added
5250 *
53- * Lastly, the last form of check is against the requested locale ID
54- * but with the variant/region field replaced with a `*` range.
51+ * Lastly, the last form of check is against the requested locale ID
52+ * but with the variant/region field replaced with a `*` range.
5553 *
56- * The rationale here laid out in LDML 4.4 Language Matching:
57- * "(...) normally the fall-off between the user's languages is
58- * substantially greated than regional variants."
54+ * The rationale here laid out in LDML 4.4 Language Matching:
55+ * "(...) normally the fall-off between the user's languages is
56+ * substantially greated than regional variants."
5957 *
60- * In other words, if we can't match for the given region, maybe
61- * we can match for the same language/script but other region, and
62- * it will in most cases be preferred over falling back on the next
63- * language.
58+ * In other words, if we can't match for the given region, maybe
59+ * we can match for the same language/script but other region, and
60+ * it will in most cases be preferred over falling back on the next
61+ * language.
6462 *
65- * What it does ([requested] * [available] = [supported]):
63+ * What it does ([requested] * [available] = [supported]):
6664 *
67- * ['en-AU'] * ['en-US'] = ['en-US']
68- * ['sr-RU'] * ['sr-Latn-RO'] = ['sr-Latn-RO'] // sr-RU -> sr-Latn-RU
65+ * ['en-AU'] * ['en-US'] = ['en-US']
66+ * ['sr-RU'] * ['sr-Latn-RO'] = ['sr-Latn-RO'] // sr-RU -> sr-Latn-RU
6967 *
70- * It works similarly to getParentLocales algo, except that we stop
71- * after matching against variant/region ranges and don't try to match
72- * ignoring script ranges. That means that `sr-Cyrl` will never match
73- * against `sr-Latn`.
68+ * It works similarly to getParentLocales algo, except that we stop
69+ * after matching against variant/region ranges and don't try to match
70+ * ignoring script ranges. That means that `sr-Cyrl` will never match
71+ * against `sr-Latn`.
7472 */
7573export function filterMatches (
7674 requestedLocales : Array < string > ,
0 commit comments