Skip to content

Commit 9fd41e0

Browse files
Switch to getting locales with sys-locale crate (#154)
Co-authored-by: Luke Frisken <[email protected]>
1 parent 6af1ba0 commit 9fd41e0

File tree

9 files changed

+34
-30
lines changed

9 files changed

+34
-30
lines changed

Cargo.lock

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

i18n-embed/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fluent-syntax = { workspace = true, optional = true }
2525
gettext = { workspace = true, optional = true }
2626
i18n-embed-impl = { workspace = true, optional = true }
2727
intl-memoizer = "0.5"
28-
locale_config = { version = "0.3", optional = true }
28+
sys-locale = { version = "0.3", optional = true }
2929
log = { workspace = true }
3030
notify = { version = "8.0.0", optional = true }
3131
parking_lot = { version = "0.12", optional = true }
@@ -49,7 +49,7 @@ default = ["rust-embed"]
4949
gettext-system = ["tr", "tr/gettext", "dep:gettext", "parking_lot", "i18n-embed-impl", "i18n-embed-impl/gettext-system"]
5050
fluent-system = ["fluent", "fluent-syntax", "parking_lot", "i18n-embed-impl", "i18n-embed-impl/fluent-system", "arc-swap"]
5151

52-
desktop-requester = ["locale_config"]
52+
desktop-requester = ["sys-locale"]
5353
web-sys-requester = ["web-sys"]
5454

5555
filesystem-assets = ["walkdir"]

i18n-embed/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The `i18n-embed` crate has the following optional Cargo features:
1515
+ `gettext-system`
1616
+ Enable support for the [gettext](https://www.gnu.org/software/gettext/) localization system using the [tr macro](https://docs.rs/tr/0.1.3/tr/) and the [gettext crate](https://docs.rs/gettext/0.4.0/gettext/) via the `GettextLanguageLoader`.
1717
+ `desktop-requester`
18-
+ Enables a convenience implementation of `LanguageRequester` trait called `DesktopLanguageRequester` for the desktop platform (windows, mac, linux),which makes use of the [locale_config](https://crates.io/crates/locale_config) crate for resolving the current system locale.
18+
+ Enables a convenience implementation of `LanguageRequester` trait called `DesktopLanguageRequester` for the desktop platform (windows, mac, linux),which makes use of the [sys-locale](https://crates.io/crates/sys-locale) crate for resolving the current system locale.
1919
+ `web-sys-requester`
2020
+ Enables a convenience implementation of `LanguageRequester` trait called `WebLanguageRequester` which makes use of the [web-sys](https://crates.io/crates/web-sys) crate for resolving the language being requested by the user's web browser in a WASM context.
2121

i18n-embed/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
//! [LanguageRequester](LanguageRequester) trait called
3939
//! `DesktopLanguageRequester for the desktop platform (windows,
4040
//! mac, linux), which makes use of the
41-
//! [locale_config](https://crates.io/crates/locale_config) crate
41+
//! [sys-locale](https://crates.io/crates/sys-locale) crate
4242
//! for resolving the current system locale.
4343
//! + `web-sys-requester`
4444
//! + Enables a convenience implementation of

i18n-embed/src/requester.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl std::fmt::Debug for LanguageRequesterImpl<'_> {
222222

223223
/// A [LanguageRequester](LanguageRequester) for the desktop platform,
224224
/// supporting windows, linux and mac. It uses
225-
/// [locale_config](locale_config) to select the language based on the
225+
/// [sys-locale](sys-locale) to select the language based on the
226226
/// system selected language.
227227
///
228228
/// ⚠️ *This API requires the following crate features to be activated: `desktop-requester`.*
@@ -283,16 +283,11 @@ impl DesktopLanguageRequester<'_> {
283283
}
284284

285285
/// The languages being requested by the operating
286-
/// system/environment according to the [locale_config] crate's
286+
/// system/environment according to the [sys-locale] crate's
287287
/// implementation.
288288
pub fn requested_languages() -> Vec<unic_langid::LanguageIdentifier> {
289-
use locale_config::{LanguageRange, Locale};
290-
291-
let current_locale = Locale::current();
292-
293-
let ids: Vec<unic_langid::LanguageIdentifier> = current_locale
294-
.tags_for("messages")
295-
.filter_map(|tag: LanguageRange<'_>| match tag.to_string().parse() {
289+
let ids: Vec<unic_langid::LanguageIdentifier> = sys_locale::get_locales()
290+
.filter_map(|tag| match tag.parse() {
296291
Ok(tag) => Some(tag),
297292
Err(err) => {
298293
log::error!("Unable to parse your locale: {:?}", err);

i18n/po/de/cargo_i18n.po

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ msgid ""
3636
"inside your application.\n"
3737
"\n"
3838
"The display language used for this command is selected automatically using "
39-
"your system settings (as described at \n"
40-
"https://github.com/rust-locale/locale_config#supported-systems ) however you "
41-
"can override it using the -l, --language option.\n"
39+
"your system settings (as returned by \n"
40+
"https://github.com/1Password/sys-locale?tab=readme-ov-file#sys-locale ) "
41+
"however you can override it using the -l, --language option.\n"
4242
"\n"
4343
"Logging for this command is available using the \"env_logger\" crate. You "
4444
"can enable debug logging using \"RUST_LOG=debug cargo i18n\"."

i18n/po/fr/cargo_i18n.po

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ msgid ""
4242
"inside your application.\n"
4343
"\n"
4444
"The display language used for this command is selected automatically using "
45-
"your system settings (as described at \n"
46-
"https://github.com/rust-locale/locale_config#supported-systems ) however you "
47-
"can override it using the -l, --language option.\n"
45+
"your system settings (as returned by \n"
46+
"https://github.com/1Password/sys-locale?tab=readme-ov-file#sys-locale ) "
47+
"however you can override it using the -l, --language option.\n"
4848
"\n"
4949
"Logging for this command is available using the \"env_logger\" crate. You "
5050
"can enable debug logging using \"RUST_LOG=debug cargo i18n\"."
@@ -65,9 +65,9 @@ msgstr ""
6565
"les localisations dans votre application.\n"
6666
"\n"
6767
"La langue d'affichage utilisée pour cette commande est sélectionnée "
68-
"automatiquement à l'aide des paramètres de votre système (comme décrit dans\n"
69-
"https://github.com/rust-locale/locale_config#supported-systems ) mais vous "
70-
"pouvez le remplacer en utilisant l'option -l, --language.\n"
68+
"automatiquement à l'aide des paramètres de votre système (comme retourné par\n"
69+
"https://github.com/1Password/sys-locale?tab=readme-ov-file#sys-locale )\n"
70+
"mais vous pouvez le remplacer en utilisant l'option -l, --language.\n"
7171
"\n"
7272
"La journalisation de cette commande est disponible à l'aide de la caisse "
7373
"\"env_logger\". Vous pouvez activer la journalisation de débogage en "

i18n/po/ru/cargo_i18n.po

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ msgid ""
3434
"inside your application.\n"
3535
"\n"
3636
"The display language used for this command is selected automatically using "
37-
"your system settings (as described at \n"
38-
"https://github.com/rust-locale/locale_config#supported-systems ) however you "
39-
"can override it using the -l, --language option.\n"
37+
"your system settings (as returned by \n"
38+
"https://github.com/1Password/sys-locale?tab=readme-ov-file#sys-locale ) "
39+
"however you can override it using the -l, --language option.\n"
4040
"\n"
4141
"Logging for this command is available using the \"env_logger\" crate. You "
4242
"can enable debug logging using \"RUST_LOG=debug cargo i18n\"."
@@ -56,9 +56,9 @@ msgstr ""
5656
"локализаций в ваше приложение.\n"
5757
"\n"
5858
"Язык отображения, используемый для этой команды, выбирается автоматически с "
59-
"использованием системных настроек (как описано в\n"
60-
"https://github.com/rust-locale/locale_config#supported-systems ) однако вы "
61-
"можете переопределить его, используя -l, --language option.\n"
59+
"использованием системных настроек (как возвращается\n"
60+
"https://github.com/1Password/sys-locale?tab=readme-ov-file#sys-locale ) однако "
61+
"вы можете переопределить его, используя опцию -l, --language.\n"
6262
"\n"
6363
"Протоколирование для этой команды доступно с использованием крэйтора "
6464
"\"env_logger\". Вы можете включить протоколирование отладки, используя "

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ localizations inside your application.
6363
6464
The display language used for this command is selected automatically \
6565
using your system settings (as described at
66-
https://github.com/rust-locale/locale_config#supported-systems ) \
66+
https://github.com/1Password/sys-locale?tab=readme-ov-file#sys-locale ) \
6767
however you can override it using the -l, --language option.
6868
6969
Logging for this command is available using the \"env_logger\" crate. \

0 commit comments

Comments
 (0)