Skip to content

Commit 5ea2fe7

Browse files
committed
fallback
1 parent 5a3c265 commit 5ea2fe7

File tree

4 files changed

+58
-14
lines changed

4 files changed

+58
-14
lines changed

provider/data/collator/data/collation_reordering_v1.rs.data

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provider/data/collator/data/collation_tailoring_v1.rs.data

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provider/data/collator/fingerprints.csv

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ collation/metadata/v1, vi, -> ee
119119
collation/metadata/v1, vi/trad, -> ee
120120
collation/metadata/v1, wo, -> af
121121
collation/metadata/v1, yo, -> af
122-
collation/reordering/v1, <lookup>, 320B, 59 identifiers
122+
collation/reordering/v1, <lookup>, 348B, 60 identifiers
123123
collation/reordering/v1, <total>, 9464B, 8024B, 30 unique payloads
124124
collation/reordering/v1, am, 320B, 272B, 3989bb25c1c894c
125125
collation/reordering/v1, ar, 312B, 264B, 44ac22224ef1784d
@@ -167,6 +167,7 @@ collation/reordering/v1, ru, -> be
167167
collation/reordering/v1, si, 316B, 268B, 76e6c2377e3f318f
168168
collation/reordering/v1, si/dict, -> si
169169
collation/reordering/v1, sr, -> be
170+
collation/reordering/v1, sr-Cyrl-ME, -> az
170171
collation/reordering/v1, sr-Latn, -> az
171172
collation/reordering/v1, ta, 316B, 268B, b337e265c95fe58e
172173
collation/reordering/v1, te, 316B, 268B, 53be041ee9b02cf9
@@ -182,7 +183,7 @@ collation/reordering/v1, und-Hant, -> und-Hani/stroke
182183
collation/reordering/v1, ur, -> ar
183184
collation/root/v1, <singleton>, 131040B, 130923B, 787ce37ea65e1e9
184185
collation/special/primaries/v1, <singleton>, 72B, 42B, 46181a77c61fe445
185-
collation/tailoring/v1, <lookup>, 608B, 102 identifiers
186+
collation/tailoring/v1, <lookup>, 618B, 103 identifiers
186187
collation/tailoring/v1, <total>, 920210B, 908458B, 93 unique payloads
187188
collation/tailoring/v1, af, 1004B, 877B, 8e3ca7ba0c0efe4b
188189
collation/tailoring/v1, ar, 8112B, 7987B, f87603c60cb612d4
@@ -260,6 +261,7 @@ collation/tailoring/v1, sk, 968B, 842B, ab8b5cec368b01e7
260261
collation/tailoring/v1, sl, 1112B, 985B, 3d4815266923b35f
261262
collation/tailoring/v1, sq, 1144B, 1018B, 60fb9f14b8173e05
262263
collation/tailoring/v1, sr, -> bs-Cyrl
264+
collation/tailoring/v1, sr-Cyrl-ME, -> bs
263265
collation/tailoring/v1, sr-Latn, -> bs
264266
collation/tailoring/v1, sv, 1742B, 1616B, 7ec4028488f2d504
265267
collation/tailoring/v1, sv/trad, 1742B, 1616B, 31420d06d80b25bb

provider/source/src/collator/mod.rs

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ use crate::IterableDataProviderCached;
99
use crate::SourceDataProvider;
1010
use icu::collator::provider::*;
1111
use icu::collections::codepointtrie::CodePointTrie;
12-
use icu::locale::subtags::{language, script};
12+
use icu::locale::{
13+
locale,
14+
subtags::{language, script},
15+
};
1316
#[cfg(any(feature = "use_wasm", feature = "use_icu4c"))]
1417
use icu_codepointtrie_builder::CodePointTrieBuilder;
1518
use icu_provider::prelude::*;
@@ -30,16 +33,19 @@ fn id_to_file_name(id: DataIdentifierBorrowed) -> String {
3033
.replace("posix", "POSIX")
3134
};
3235

33-
// und-Hant -> zh_stroke
34-
// und-Hans -> zh_pinyin
35-
// und-Hani/x -> zh_x
36+
// und_Hant -> zh_stroke
37+
// und_Hans -> zh_pinyin
38+
// und_Hani/x -> zh_x
39+
// sr_Cyrl_ME -> sr_Latn
3640

3741
if s == "und_Hant" {
3842
return "zh_stroke".into();
3943
} else if s == "und_Hans" {
4044
return "zh_pinyin".into();
4145
} else if s == "und_Hani" {
4246
s = "zh".into();
47+
} else if s == "sr_Cyrl_ME" {
48+
s = "sr_Latn".into();
4349
}
4450

4551
s.push('_');
@@ -53,7 +59,7 @@ fn id_to_file_name(id: DataIdentifierBorrowed) -> String {
5359
s
5460
}
5561

56-
fn file_name_to_id(file_name: &str) -> Vec<DataIdentifierCow<'static>> {
62+
fn file_name_to_ids(file_name: &str) -> Vec<DataIdentifierCow<'static>> {
5763
let (mut language, mut variant) = file_name.rsplit_once('_').unwrap();
5864
if language == "root" {
5965
language = "und";
@@ -72,19 +78,27 @@ fn file_name_to_id(file_name: &str) -> Vec<DataIdentifierCow<'static>> {
7278
// Pinyin is stored in both und-Hans and und-Hani/pinyin
7379
r.push(DataIdentifierCow::from_borrowed_and_owned(
7480
Default::default(),
75-
"und-Hans".parse().unwrap(),
81+
locale!("und-Hans").into(),
7682
));
7783
} else if variant == "stroke" {
7884
// Stroke is stored in both und-Hans and und-Hani/stroke
7985
r.push(DataIdentifierCow::from_borrowed_and_owned(
8086
Default::default(),
81-
"und-Hant".parse().unwrap(),
87+
locale!("und-Hant").into(),
8288
));
8389
}
8490
} else if variant == "standard" {
8591
variant = "";
8692
}
8793

94+
if language == "sr_Latn" {
95+
// sr_Cyrl_ME falls back to sr_ME, which falls back to sr_Latn.
96+
r.push(DataIdentifierCow::from_borrowed_and_owned(
97+
Default::default(),
98+
locale!("sr-Cyrl-ME").into(),
99+
));
100+
}
101+
88102
let marker_attributes = match variant {
89103
"traditional" => DataMarkerAttributes::from_str_or_panic("trad").to_owned(),
90104
"phonebook" => DataMarkerAttributes::from_str_or_panic("phonebk").to_owned(),
@@ -99,6 +113,34 @@ fn file_name_to_id(file_name: &str) -> Vec<DataIdentifierCow<'static>> {
99113
r
100114
}
101115

116+
#[test]
117+
fn test_all_fallback_overrides_handled() {
118+
let provider = SourceDataProvider::new_testing();
119+
let required_overrides = provider
120+
.cldr().unwrap()
121+
.core()
122+
.read_and_parse::<super::cldr_serde::parent_locales::Resource>(
123+
"supplemental/parentLocales.json",
124+
)
125+
.unwrap()
126+
.supplemental
127+
.parent_locales
128+
.collations
129+
.keys()
130+
.collect::<Vec<_>>();
131+
132+
let handled_overrides = [
133+
"sr-Cyrl-ME",
134+
"yue",
135+
"yue-CN",
136+
"yue-Hans",
137+
"yue-Hans-CN",
138+
"yue-Hant",
139+
];
140+
141+
assert_eq!(required_overrides, handled_overrides);
142+
}
143+
102144
impl SourceDataProvider {
103145
fn load_toml<T>(&self, id: DataIdentifierBorrowed, suffix: &str) -> Result<&T, DataError>
104146
where
@@ -130,7 +172,7 @@ impl SourceDataProvider {
130172
file_name
131173
})
132174
})
133-
.flat_map(|s| file_name_to_id(&s))
175+
.flat_map(|s| file_name_to_ids(&s))
134176
.collect())
135177
}
136178
}

0 commit comments

Comments
 (0)