Skip to content

Commit fbc93c5

Browse files
committed
Rollup merge of #104047 - crlf0710:icu_based_list_formatting, r=davidtwco
Diagnostics `icu4x` based list formatting. This adds a new kind of `DiagnosticArg` and add the ability to convert it to a `FluentValue::Custom`. When emitting fluent output, it makes use of `ListFormatter` from `icu4x` project to convert it to localized version of list following the fluent locale, as a kind of eager translation. Tested locally with locales like `en`, `ja`, etc, and they work fine. <del>Though neither `zh-CN` nor `zh-Hans` works correctly, it seems they fallback to `und` locale somehow, emitting only comma-based list. I believe this is an internal issue of `icu4x` itself.</del>(Works fine after #104047 (comment)) Would love to hear what others think. r? `@davidtwco` cc `@Manishearth`
2 parents a396240 + d75c76d commit fbc93c5

File tree

19 files changed

+2644
-23
lines changed

19 files changed

+2644
-23
lines changed

Cargo.lock

+176-2
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223"
211211
dependencies = [
212212
"lazy_static",
213213
"memchr",
214-
"regex-automata",
214+
"regex-automata 0.1.10",
215215
]
216216

217217
[[package]]
@@ -1710,6 +1710,73 @@ version = "2.0.1"
17101710
source = "registry+https://github.com/rust-lang/crates.io-index"
17111711
checksum = "3c1ad908cc71012b7bea4d0c53ba96a8cba9962f048fa68d143376143d863b7a"
17121712

1713+
[[package]]
1714+
name = "icu_list"
1715+
version = "1.0.0"
1716+
source = "registry+https://github.com/rust-lang/crates.io-index"
1717+
checksum = "c40218275f081c4493f190357c5395647b06734c2dc3dcb41cc099a0f60168b1"
1718+
dependencies = [
1719+
"displaydoc",
1720+
"icu_locid",
1721+
"icu_provider",
1722+
"regex-automata 0.2.0",
1723+
"writeable",
1724+
"zerovec",
1725+
]
1726+
1727+
[[package]]
1728+
name = "icu_locid"
1729+
version = "1.0.0"
1730+
source = "registry+https://github.com/rust-lang/crates.io-index"
1731+
checksum = "34b3de5d99a0e275fe6193b9586dbf37364daebc0d39c89b5cf8376a53b789e8"
1732+
dependencies = [
1733+
"displaydoc",
1734+
"litemap",
1735+
"tinystr",
1736+
"writeable",
1737+
"zerovec",
1738+
]
1739+
1740+
[[package]]
1741+
name = "icu_provider"
1742+
version = "1.0.1"
1743+
source = "registry+https://github.com/rust-lang/crates.io-index"
1744+
checksum = "2f911086e3c521a8a824d4f8bfd87769645ced2f07ff913b521c0d793be07100"
1745+
dependencies = [
1746+
"displaydoc",
1747+
"icu_locid",
1748+
"icu_provider_macros",
1749+
"stable_deref_trait",
1750+
"writeable",
1751+
"yoke",
1752+
"zerofrom",
1753+
"zerovec",
1754+
]
1755+
1756+
[[package]]
1757+
name = "icu_provider_adapters"
1758+
version = "1.0.0"
1759+
source = "registry+https://github.com/rust-lang/crates.io-index"
1760+
checksum = "980c71d8a91b246ebbb97847178a4b816eea39d1d550c70ee566384555bb6545"
1761+
dependencies = [
1762+
"icu_locid",
1763+
"icu_provider",
1764+
"tinystr",
1765+
"yoke",
1766+
"zerovec",
1767+
]
1768+
1769+
[[package]]
1770+
name = "icu_provider_macros"
1771+
version = "1.0.0"
1772+
source = "registry+https://github.com/rust-lang/crates.io-index"
1773+
checksum = "38cf6f5b65cf81f0b4298da647101acbfe6ae0e25263f92bd7a22597e9d6d606"
1774+
dependencies = [
1775+
"proc-macro2",
1776+
"quote",
1777+
"syn",
1778+
]
1779+
17131780
[[package]]
17141781
name = "idna"
17151782
version = "0.2.0"
@@ -2037,6 +2104,12 @@ dependencies = [
20372104
"walkdir",
20382105
]
20392106

2107+
[[package]]
2108+
name = "litemap"
2109+
version = "0.6.0"
2110+
source = "registry+https://github.com/rust-lang/crates.io-index"
2111+
checksum = "f34a3f4798fac63fb48cf277eefa38f94d3443baff555bb98e4f56bc9092368e"
2112+
20402113
[[package]]
20412114
name = "lld-wrapper"
20422115
version = "0.1.0"
@@ -2103,7 +2176,7 @@ version = "0.1.0"
21032176
source = "registry+https://github.com/rust-lang/crates.io-index"
21042177
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
21052178
dependencies = [
2106-
"regex-automata",
2179+
"regex-automata 0.1.10",
21072180
]
21082181

21092182
[[package]]
@@ -2930,6 +3003,15 @@ dependencies = [
29303003
"regex-syntax",
29313004
]
29323005

3006+
[[package]]
3007+
name = "regex-automata"
3008+
version = "0.2.0"
3009+
source = "registry+https://github.com/rust-lang/crates.io-index"
3010+
checksum = "e9368763f5a9b804326f3af749e16f9abf378d227bcdee7634b13d8f17793782"
3011+
dependencies = [
3012+
"memchr",
3013+
]
3014+
29333015
[[package]]
29343016
name = "regex-syntax"
29353017
version = "0.6.26"
@@ -3204,6 +3286,18 @@ dependencies = [
32043286
"rustc_span",
32053287
]
32063288

3289+
[[package]]
3290+
name = "rustc_baked_icu_data"
3291+
version = "0.0.0"
3292+
dependencies = [
3293+
"icu_list",
3294+
"icu_locid",
3295+
"icu_provider",
3296+
"icu_provider_adapters",
3297+
"litemap",
3298+
"zerovec",
3299+
]
3300+
32073301
[[package]]
32083302
name = "rustc_borrowck"
32093303
version = "0.0.0"
@@ -3424,13 +3518,18 @@ version = "0.0.0"
34243518
dependencies = [
34253519
"fluent-bundle",
34263520
"fluent-syntax",
3521+
"icu_list",
3522+
"icu_locid",
3523+
"icu_provider_adapters",
34273524
"intl-memoizer",
3525+
"rustc_baked_icu_data",
34283526
"rustc_data_structures",
34293527
"rustc_macros",
34303528
"rustc_serialize",
34313529
"rustc_span",
34323530
"tracing",
34333531
"unic-langid",
3532+
"writeable",
34343533
]
34353534

34363535
[[package]]
@@ -4934,6 +5033,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
49345033
checksum = "f8aeafdfd935e4a7fe16a91ab711fa52d54df84f9c8f7ca5837a9d1d902ef4c2"
49355034
dependencies = [
49365035
"displaydoc",
5036+
"zerovec",
49375037
]
49385038

49395039
[[package]]
@@ -5544,6 +5644,12 @@ version = "0.42.0"
55445644
source = "registry+https://github.com/rust-lang/crates.io-index"
55455645
checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5"
55465646

5647+
[[package]]
5648+
name = "writeable"
5649+
version = "0.5.0"
5650+
source = "registry+https://github.com/rust-lang/crates.io-index"
5651+
checksum = "f8e6ab4f5da1b24daf2c590cfac801bacb27b15b4f050e84eb60149ea726f06b"
5652+
55475653
[[package]]
55485654
name = "xattr"
55495655
version = "0.2.2"
@@ -5596,3 +5702,71 @@ checksum = "fe5c30ade05e61656247b2e334a031dfd0cc466fadef865bdcdea8d537951bf1"
55965702
dependencies = [
55975703
"winapi",
55985704
]
5705+
5706+
[[package]]
5707+
name = "yoke"
5708+
version = "0.6.2"
5709+
source = "registry+https://github.com/rust-lang/crates.io-index"
5710+
checksum = "1fe1d55ca72c32d573bfbd5cb2f0ca65a497854c44762957a6d3da96041a5184"
5711+
dependencies = [
5712+
"serde",
5713+
"stable_deref_trait",
5714+
"yoke-derive",
5715+
"zerofrom",
5716+
]
5717+
5718+
[[package]]
5719+
name = "yoke-derive"
5720+
version = "0.6.1"
5721+
source = "registry+https://github.com/rust-lang/crates.io-index"
5722+
checksum = "1346e4cd025ae818b88566eac7eb65ab33a994ea55f355c86889af2e7e56b14e"
5723+
dependencies = [
5724+
"proc-macro2",
5725+
"quote",
5726+
"syn",
5727+
"synstructure",
5728+
]
5729+
5730+
[[package]]
5731+
name = "zerofrom"
5732+
version = "0.1.1"
5733+
source = "registry+https://github.com/rust-lang/crates.io-index"
5734+
checksum = "79e9355fccf72b04b7deaa99ce7a0f6630530acf34045391b74460fcd714de54"
5735+
dependencies = [
5736+
"zerofrom-derive",
5737+
]
5738+
5739+
[[package]]
5740+
name = "zerofrom-derive"
5741+
version = "0.1.1"
5742+
source = "registry+https://github.com/rust-lang/crates.io-index"
5743+
checksum = "2e8aa86add9ddbd2409c1ed01e033cd457d79b1b1229b64922c25095c595e829"
5744+
dependencies = [
5745+
"proc-macro2",
5746+
"quote",
5747+
"syn",
5748+
"synstructure",
5749+
]
5750+
5751+
[[package]]
5752+
name = "zerovec"
5753+
version = "0.9.0"
5754+
source = "registry+https://github.com/rust-lang/crates.io-index"
5755+
checksum = "b9d919a74c17749ccb17beaf6405562e413cd94e98ba52ca1e64bbe7eefbd8b8"
5756+
dependencies = [
5757+
"yoke",
5758+
"zerofrom",
5759+
"zerovec-derive",
5760+
]
5761+
5762+
[[package]]
5763+
name = "zerovec-derive"
5764+
version = "0.9.0"
5765+
source = "registry+https://github.com/rust-lang/crates.io-index"
5766+
checksum = "490e5f878c2856225e884c35927e7ea6db3c24cdb7229b72542c7526ad7ed49e"
5767+
dependencies = [
5768+
"proc-macro2",
5769+
"quote",
5770+
"syn",
5771+
"synstructure",
5772+
]
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "rustc_baked_icu_data"
3+
version = "0.0.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
icu_list = "1.0.0"
8+
icu_locid = "1.0.0"
9+
icu_provider = "1.0.1"
10+
icu_provider_adapters = "1.0.0"
11+
litemap = "0.6.0"
12+
zerovec = "0.9.0"
13+
14+
[features]
15+
rustc_use_parallel_compiler = ['icu_provider/sync']
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// @generated
2+
impl AnyProvider for BakedDataProvider {
3+
fn load_any(&self, key: DataKey, req: DataRequest) -> Result<AnyResponse, DataError> {
4+
const ANDLISTV1MARKER: ::icu_provider::DataKeyHash =
5+
::icu_list::provider::AndListV1Marker::KEY.hashed();
6+
const COLLATIONFALLBACKSUPPLEMENTV1MARKER: ::icu_provider::DataKeyHash =
7+
::icu_provider_adapters::fallback::provider::CollationFallbackSupplementV1Marker::KEY
8+
.hashed();
9+
const LOCALEFALLBACKLIKELYSUBTAGSV1MARKER: ::icu_provider::DataKeyHash =
10+
::icu_provider_adapters::fallback::provider::LocaleFallbackLikelySubtagsV1Marker::KEY
11+
.hashed();
12+
const LOCALEFALLBACKPARENTSV1MARKER: ::icu_provider::DataKeyHash =
13+
::icu_provider_adapters::fallback::provider::LocaleFallbackParentsV1Marker::KEY
14+
.hashed();
15+
#[allow(clippy::match_single_binding)]
16+
match key.hashed() {
17+
ANDLISTV1MARKER => list::and_v1::DATA
18+
.get_by(|k| req.locale.strict_cmp(k.as_bytes()).reverse())
19+
.copied()
20+
.map(AnyPayload::from_static_ref)
21+
.ok_or(DataErrorKind::MissingLocale),
22+
COLLATIONFALLBACKSUPPLEMENTV1MARKER => fallback::supplement::co_v1::DATA
23+
.get_by(|k| req.locale.strict_cmp(k.as_bytes()).reverse())
24+
.copied()
25+
.map(AnyPayload::from_static_ref)
26+
.ok_or(DataErrorKind::MissingLocale),
27+
LOCALEFALLBACKLIKELYSUBTAGSV1MARKER => fallback::likelysubtags_v1::DATA
28+
.get_by(|k| req.locale.strict_cmp(k.as_bytes()).reverse())
29+
.copied()
30+
.map(AnyPayload::from_static_ref)
31+
.ok_or(DataErrorKind::MissingLocale),
32+
LOCALEFALLBACKPARENTSV1MARKER => fallback::parents_v1::DATA
33+
.get_by(|k| req.locale.strict_cmp(k.as_bytes()).reverse())
34+
.copied()
35+
.map(AnyPayload::from_static_ref)
36+
.ok_or(DataErrorKind::MissingLocale),
37+
_ => Err(DataErrorKind::MissingDataKey),
38+
}
39+
.map_err(|e| e.with_req(key, req))
40+
.map(|payload| AnyResponse { payload: Some(payload), metadata: Default::default() })
41+
}
42+
}

0 commit comments

Comments
 (0)