Skip to content

Commit 66d26af

Browse files
authored
Rollup merge of rust-lang#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 rust-lang#104047 (comment)) Would love to hear what others think. r? ``@davidtwco`` cc ``@Manishearth``
2 parents b04b762 + d75c76d commit 66d26af

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]]
@@ -1707,6 +1707,73 @@ version = "2.0.1"
17071707
source = "registry+https://github.com/rust-lang/crates.io-index"
17081708
checksum = "3c1ad908cc71012b7bea4d0c53ba96a8cba9962f048fa68d143376143d863b7a"
17091709

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

2104+
[[package]]
2105+
name = "litemap"
2106+
version = "0.6.0"
2107+
source = "registry+https://github.com/rust-lang/crates.io-index"
2108+
checksum = "f34a3f4798fac63fb48cf277eefa38f94d3443baff555bb98e4f56bc9092368e"
2109+
20372110
[[package]]
20382111
name = "lld-wrapper"
20392112
version = "0.1.0"
@@ -2100,7 +2173,7 @@ version = "0.1.0"
21002173
source = "registry+https://github.com/rust-lang/crates.io-index"
21012174
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
21022175
dependencies = [
2103-
"regex-automata",
2176+
"regex-automata 0.1.10",
21042177
]
21052178

21062179
[[package]]
@@ -2927,6 +3000,15 @@ dependencies = [
29273000
"regex-syntax",
29283001
]
29293002

3003+
[[package]]
3004+
name = "regex-automata"
3005+
version = "0.2.0"
3006+
source = "registry+https://github.com/rust-lang/crates.io-index"
3007+
checksum = "e9368763f5a9b804326f3af749e16f9abf378d227bcdee7634b13d8f17793782"
3008+
dependencies = [
3009+
"memchr",
3010+
]
3011+
29303012
[[package]]
29313013
name = "regex-syntax"
29323014
version = "0.6.26"
@@ -3202,6 +3284,18 @@ dependencies = [
32023284
"rustc_span",
32033285
]
32043286

3287+
[[package]]
3288+
name = "rustc_baked_icu_data"
3289+
version = "0.0.0"
3290+
dependencies = [
3291+
"icu_list",
3292+
"icu_locid",
3293+
"icu_provider",
3294+
"icu_provider_adapters",
3295+
"litemap",
3296+
"zerovec",
3297+
]
3298+
32053299
[[package]]
32063300
name = "rustc_borrowck"
32073301
version = "0.0.0"
@@ -3422,13 +3516,18 @@ version = "0.0.0"
34223516
dependencies = [
34233517
"fluent-bundle",
34243518
"fluent-syntax",
3519+
"icu_list",
3520+
"icu_locid",
3521+
"icu_provider_adapters",
34253522
"intl-memoizer",
3523+
"rustc_baked_icu_data",
34263524
"rustc_data_structures",
34273525
"rustc_macros",
34283526
"rustc_serialize",
34293527
"rustc_span",
34303528
"tracing",
34313529
"unic-langid",
3530+
"writeable",
34323531
]
34333532

34343533
[[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]]
@@ -5546,6 +5646,12 @@ version = "0.42.0"
55465646
source = "registry+https://github.com/rust-lang/crates.io-index"
55475647
checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5"
55485648

5649+
[[package]]
5650+
name = "writeable"
5651+
version = "0.5.0"
5652+
source = "registry+https://github.com/rust-lang/crates.io-index"
5653+
checksum = "f8e6ab4f5da1b24daf2c590cfac801bacb27b15b4f050e84eb60149ea726f06b"
5654+
55495655
[[package]]
55505656
name = "xattr"
55515657
version = "0.2.2"
@@ -5598,3 +5704,71 @@ checksum = "fe5c30ade05e61656247b2e334a031dfd0cc466fadef865bdcdea8d537951bf1"
55985704
dependencies = [
55995705
"winapi",
56005706
]
5707+
5708+
[[package]]
5709+
name = "yoke"
5710+
version = "0.6.2"
5711+
source = "registry+https://github.com/rust-lang/crates.io-index"
5712+
checksum = "1fe1d55ca72c32d573bfbd5cb2f0ca65a497854c44762957a6d3da96041a5184"
5713+
dependencies = [
5714+
"serde",
5715+
"stable_deref_trait",
5716+
"yoke-derive",
5717+
"zerofrom",
5718+
]
5719+
5720+
[[package]]
5721+
name = "yoke-derive"
5722+
version = "0.6.1"
5723+
source = "registry+https://github.com/rust-lang/crates.io-index"
5724+
checksum = "1346e4cd025ae818b88566eac7eb65ab33a994ea55f355c86889af2e7e56b14e"
5725+
dependencies = [
5726+
"proc-macro2",
5727+
"quote",
5728+
"syn",
5729+
"synstructure",
5730+
]
5731+
5732+
[[package]]
5733+
name = "zerofrom"
5734+
version = "0.1.1"
5735+
source = "registry+https://github.com/rust-lang/crates.io-index"
5736+
checksum = "79e9355fccf72b04b7deaa99ce7a0f6630530acf34045391b74460fcd714de54"
5737+
dependencies = [
5738+
"zerofrom-derive",
5739+
]
5740+
5741+
[[package]]
5742+
name = "zerofrom-derive"
5743+
version = "0.1.1"
5744+
source = "registry+https://github.com/rust-lang/crates.io-index"
5745+
checksum = "2e8aa86add9ddbd2409c1ed01e033cd457d79b1b1229b64922c25095c595e829"
5746+
dependencies = [
5747+
"proc-macro2",
5748+
"quote",
5749+
"syn",
5750+
"synstructure",
5751+
]
5752+
5753+
[[package]]
5754+
name = "zerovec"
5755+
version = "0.9.0"
5756+
source = "registry+https://github.com/rust-lang/crates.io-index"
5757+
checksum = "b9d919a74c17749ccb17beaf6405562e413cd94e98ba52ca1e64bbe7eefbd8b8"
5758+
dependencies = [
5759+
"yoke",
5760+
"zerofrom",
5761+
"zerovec-derive",
5762+
]
5763+
5764+
[[package]]
5765+
name = "zerovec-derive"
5766+
version = "0.9.0"
5767+
source = "registry+https://github.com/rust-lang/crates.io-index"
5768+
checksum = "490e5f878c2856225e884c35927e7ea6db3c24cdb7229b72542c7526ad7ed49e"
5769+
dependencies = [
5770+
"proc-macro2",
5771+
"quote",
5772+
"syn",
5773+
"synstructure",
5774+
]
+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)