Since env_preferences
is not on crates.io, this functionality has been cut for the 0.1.0 release and will be added back in a future version. This also greatly simplifies the dependencies and should make things much faster to build, as the icu crates are now merged back into the dependency graph instead of being special-cased git dependencies.
X6AMFX3NNMVV7NXWT3KM6IEXE3UX67W7C7NPPVZA7YH2B3F6NOPAC
RUCC2HKZZTUHN3G6IWS4NK3VYGXAI6PORJH2YZKPRAYSDWH63ESQC
UN2XEIEUIB4ERS3IXOHQT2GCPBKK3JKHCGEVKQFP4SCV5AONFXMQC
HHJDRLLNN36UNIA7STAXEEVBCEMPJNB7SJQOS3TJLLYN4AEZ4MHQC
7M4UI3TWQIAA333GQ577HDWDWZPSZKWCYG556L6SBRLB6SZDQYPAC
QJC4IQITOQP65AFLA5CMH2EXHB6B3SOLW2XBV72U5ZQU2KOR2EIAC
6XEMHUGSNX5YSWZYM7PZUTTUMFODMGO74QLHGEXQ5LAC7LPS7JNQC
VJCANIBGGIS7ICGVKKD637ULAFZCWPL3NZWSKZTCA4BQWV4OSDJQC
3NMKD6I57ONAGHEN4PZIAV2KPYESVR4JL3DTWSHXKCMVJBEQ4GIQC
U2PHMYPDFQQYTPDVVJLWDJM5G45ILXLWDDDTZVV2NBOSCED323MQC
AE3AZFVKJBURLY6T6H5477BSP5LISUQYPSPDRSPXRO435KGYTRZAC
FDFI4WMO7JJCQ3CM5G7QDMXN5ZUJAUED7G64II55XUXHT4IWZAXAC
GJMBIJOE47X7DKZDHIY6VQ2ISC52XAVAV46L6PJQZTV7L7DDSWOAC
S26YOXQIUO3B7FCWZ33RI54OHFVXUDSFKBMVAAND3BW3H5WRGNRAC
VZYZRAO4EXCHW2LBVFG5ELSWG5SCNDREMJ6RKQ4EKQGI2T7SD3ZQC
VQBJBFEXRTJDBH27SVWRBCBFC7OOFOZ3DSMX7PE5BIZQLGHPVDYAC
UKFEFT6LSI4K7X6UHQFZYD52DILKXMZMYSO2UYS2FCHNPXIF4BEQC
JUV7C6ET4ZQJNLO7B4JB7XMLV2YUBZB4ARJHN4JEPHDGGBWGLEVAC
QBPLOFFIOEDXJ4TR5KBN3DQ4NAW3AE6C6RXE73ZGNJYDNKWN3R6QC
LYZBTYIWMOD3YTMOTBJBRNVYR7JOKVVGSHCFALKLGJO3IXTJC6HQC
XGRU7WZEM6PTUCSHUA6QGNK7N34M7OPE52BTDC33BHSUEWM6B4FAC
F5LG7WENUUDRSCTDMA4M6BAC5RWTGQO45C4ZEBZDX6FHCTTHBVGQC
fn localize(&self) -> String {
let system_locales =
env_preferences::get_locales_lossy().unwrap_or(vec![self.canonical_locale()]);
let requested_locales = old_locale_version(system_locales);
let available_locales = old_locale_version(self.available_locales());
let canonical_locale =
icu_locid::Locale::try_from_bytes(self.canonical_locale().to_string().as_bytes())
.unwrap();
let selected_locale = fluent_langneg::negotiate_languages(
&requested_locales,
&available_locales,
Some(&canonical_locale),
NegotiationStrategy::Matching,
);
self.message_for_locale(&Locale::try_from_str(&selected_locale[0].to_string()).unwrap())
}
}
// TODO: remove this hack
fn old_locale_version(new_locales: Vec<icu_locale_core::Locale>) -> Vec<icu_locid::Locale> {
new_locales
.into_iter()
// Convert new `icu_locale::Locale` to canonical string
.map(|icu_langid| icu_langid.to_string())
// Convert canonical string to old `icu_locid` for `fluent_langneg`
.map(|icu_langid| icu_locid::Locale::try_from_bytes(icu_langid.as_bytes()))
.map(Result::unwrap)
.collect::<_>()
# ICU4X crates (env_preferences is not publicly released, so depend on the latest git tag instead)
env_preferences = { version = "0.1.0", git = "https://github.com/unicode-org/icu4x", tag = "icu@2.0.0" }
fixed_decimal = { version = "0.7.0", git = "https://github.com/unicode-org/icu4x", tag = "icu@2.0.0", features = [
"ryu",
] }
icu_decimal = { version = "2.0.0", git = "https://github.com/unicode-org/icu4x", tag = "icu@2.0.0" }
icu_experimental = { version = "0.3.0", git = "https://github.com/unicode-org/icu4x", tag = "icu@2.0.0" }
icu_locale = { version = "2.0.0", git = "https://github.com/unicode-org/icu4x", tag = "icu@2.0.0" }
icu_locale_core = { version = "2.0.0", git = "https://github.com/unicode-org/icu4x", tag = "icu@2.0.0" }
icu_plurals = { version = "2.0.0", git = "https://github.com/unicode-org/icu4x", tag = "icu@2.0.0" }
[[package]]
name = "env_preferences"
version = "0.1.0"
source = "git+https://github.com/unicode-org/icu4x?tag=icu%402.0.0#5e404744dd6c9dd7f86aac82586e3fa98ea75f7f"
dependencies = [
"core-foundation-sys",
"displaydoc",
"icu_locale_core",
"libc",
"windows",
]
"writeable 0.6.1",
]
[[package]]
name = "fluent-langneg"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7b2da3cb6583f7e5f98d3e0e1f9ff70451398037445c8e89a0dc51594cf1736"
dependencies = [
"icu_locid",
"icu_locid_transform",
"writeable",
source = "git+https://github.com/unicode-org/icu4x?tag=icu%402.0.0#5e404744dd6c9dd7f86aac82586e3fa98ea75f7f"
[[package]]
name = "icu_locid"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637"
dependencies = [
"displaydoc",
"litemap 0.7.5",
"tinystr 0.7.6",
"writeable 0.5.5",
"zerovec 0.10.4",
]
[[package]]
name = "icu_locid_transform"
version = "1.5.0"
checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e"
dependencies = [
"displaydoc",
"icu_locid",
"icu_locid_transform_data",
"icu_provider 1.5.0",
"tinystr 0.7.6",
"zerovec 0.10.4",
]
checksum = "4fdef0c124749d06a743c69e938350816554eb63ac979166590e2b4ee4252765"
name = "icu_locid_transform_data"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7515e6d781098bf9f7205ab3fc7e9709d34554ae0b21ddbcb5febfa4bc7df11d"
[[package]]
source = "git+https://github.com/unicode-org/icu4x?tag=icu%402.0.0#5e404744dd6c9dd7f86aac82586e3fa98ea75f7f"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "983825f401e6bc4a13c45d552ffd9ad6f3f6b6bc0ec03f31d6835a90a46deb1f"
version = "2.0.0"
source = "git+https://github.com/unicode-org/icu4x?tag=icu%402.0.0#5e404744dd6c9dd7f86aac82586e3fa98ea75f7f"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "016c619c1eeb94efb86809b015c58f479963de65bdb6253345c1a1276f22e32b"
version = "2.0.0"
source = "git+https://github.com/unicode-org/icu4x?tag=icu%402.0.0#5e404744dd6c9dd7f86aac82586e3fa98ea75f7f"
[[package]]
name = "icu_provider"
version = "1.5.0"
version = "2.0.1"
checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9"
dependencies = [
"displaydoc",
"icu_locid",
"icu_provider_macros",
"stable_deref_trait",
"tinystr 0.7.6",
"writeable 0.5.5",
"yoke 0.7.5",
"zerofrom 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"zerovec 0.10.4",
]
checksum = "298459143998310acd25ffe6810ed544932242d3f07083eee1084d83a71bd632"
"tinystr 0.8.1",
"writeable 0.6.1",
"yoke 0.8.0",
"zerofrom 0.1.6 (git+https://github.com/unicode-org/icu4x?tag=icu%402.0.0)",
"tinystr",
"writeable",
"yoke",
"zerofrom",
name = "icu_provider_macros"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "litemap"
version = "0.8.0"
source = "git+https://github.com/unicode-org/icu4x?tag=icu%402.0.0#5e404744dd6c9dd7f86aac82586e3fa98ea75f7f"
[[package]]
source = "git+https://github.com/unicode-org/icu4x?tag=icu%402.0.0#5e404744dd6c9dd7f86aac82586e3fa98ea75f7f"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5a7c30837279ca13e7c867e9e40053bc68740f988cb07f7ca6df43cc734b585"
name = "tinystr"
version = "0.8.1"
source = "git+https://github.com/unicode-org/icu4x?tag=icu%402.0.0#5e404744dd6c9dd7f86aac82586e3fa98ea75f7f"
dependencies = [
"displaydoc",
"zerovec 0.11.2",
]
[[package]]
[[package]]
name = "windows"
version = "0.60.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddf874e74c7a99773e62b1c671427abf01a425e77c3d3fb9fb1e4883ea934529"
dependencies = [
"windows-collections",
"windows-core",
"windows-future",
"windows-link",
"windows-numerics",
]
[[package]]
name = "windows-collections"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5467f79cc1ba3f52ebb2ed41dbb459b8e7db636cc3429458d9a852e15bc24dec"
dependencies = [
"windows-core",
]
[[package]]
name = "windows-core"
version = "0.60.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca21a92a9cae9bf4ccae5cf8368dce0837100ddf6e6d57936749e85f152f6247"
dependencies = [
"windows-implement",
"windows-interface",
"windows-link",
"windows-result",
"windows-strings",
]
[[package]]
name = "windows-future"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a787db4595e7eb80239b74ce8babfb1363d8e343ab072f2ffe901400c03349f0"
dependencies = [
"windows-core",
"windows-link",
]
[[package]]
name = "windows-implement"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83577b051e2f49a058c308f17f273b570a6a758386fc291b5f6a934dd84e48c1"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "windows-interface"
version = "0.59.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "windows-link"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"
[[package]]
name = "windows-numerics"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "005dea54e2f6499f2cee279b8f703b3cf3b5734a2d8d21867c8f44003182eeed"
dependencies = [
"windows-core",
"windows-link",
]
[[package]]
name = "windows-result"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6"
dependencies = [
"windows-link",
]
name = "windows-strings"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87fa48cc5d406560701792be122a10132491cff9d0aeb23583cc2dcafc847319"
dependencies = [
"windows-link",
]
[[package]]
source = "git+https://github.com/unicode-org/icu4x?tag=icu%402.0.0#5e404744dd6c9dd7f86aac82586e3fa98ea75f7f"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea2f10b9bb0928dfb1b42b65e1f9e36f7f54dbdf08457afefb38afcdec4fa2bb"
source = "git+https://github.com/unicode-org/icu4x?tag=icu%402.0.0#5e404744dd6c9dd7f86aac82586e3fa98ea75f7f"
dependencies = [
"serde",
"stable_deref_trait",
"yoke-derive 0.8.0",
"zerofrom 0.1.6 (git+https://github.com/unicode-org/icu4x?tag=icu%402.0.0)",
]
[[package]]
name = "yoke-derive"
version = "0.7.5"
name = "yoke-derive"
version = "0.8.0"
source = "git+https://github.com/unicode-org/icu4x?tag=icu%402.0.0#5e404744dd6c9dd7f86aac82586e3fa98ea75f7f"
dependencies = [
"proc-macro2",
"quote",
"syn",
"synstructure",
]
[[package]]
dependencies = [
"zerofrom-derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "zerofrom"
version = "0.1.6"
source = "git+https://github.com/unicode-org/icu4x?tag=icu%402.0.0#5e404744dd6c9dd7f86aac82586e3fa98ea75f7f"
dependencies = [
"proc-macro2",
"quote",
"syn",
"synstructure",
]
[[package]]
name = "zerofrom-derive"
version = "0.1.6"
source = "git+https://github.com/unicode-org/icu4x?tag=icu%402.0.0#5e404744dd6c9dd7f86aac82586e3fa98ea75f7f"
source = "git+https://github.com/unicode-org/icu4x?tag=icu%402.0.0#5e404744dd6c9dd7f86aac82586e3fa98ea75f7f"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36f0bbd478583f79edad978b407914f61b2972f5af6fa089686016be8f9af595"
name = "zerovec"
version = "0.11.2"
source = "git+https://github.com/unicode-org/icu4x?tag=icu%402.0.0#5e404744dd6c9dd7f86aac82586e3fa98ea75f7f"
dependencies = [
"yoke 0.8.0",
"zerofrom 0.1.6 (git+https://github.com/unicode-org/icu4x?tag=icu%402.0.0)",
"zerovec-derive 0.11.1",
]
[[package]]
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "zerovec-derive"