diff --git a/CHANGELOG.md b/CHANGELOG.md index b09a70c109..a13d425181 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,6 +70,7 @@ You can find its changes [documented below](#070---2021-01-01). - Fixed `WindowLevel::Tooltip` on Windows platform ([#1737] by [@djeedai]) - X11 backend now supports scaling([#1751] by [@Maan2003]) - X11 backend now supports changing cursors ([#1755] by [@Maan2003]) +- X11 backend now uses the platform locale ([#1756] by [@Maan2003]) ### Visual @@ -708,6 +709,7 @@ Last release without a changelog :( [#1751]: https://github.com/linebender/druid/pull/1751 [#1754]: https://github.com/linebender/druid/pull/1754 [#1755]: https://github.com/linebender/druid/pull/1755 +[#1756]: https://github.com/linebender/druid/pull/1756 [Unreleased]: https://github.com/linebender/druid/compare/v0.7.0...master [0.7.0]: https://github.com/linebender/druid/compare/v0.6.0...v0.7.0 diff --git a/druid-shell/src/platform/x11/application.rs b/druid-shell/src/platform/x11/application.rs index 214c50c7d8..500f047513 100644 --- a/druid-shell/src/platform/x11/application.rs +++ b/druid-shell/src/platform/x11/application.rs @@ -526,9 +526,22 @@ impl Application { } pub fn get_locale() -> String { - // TODO(x11/locales): implement Application::get_locale - tracing::warn!("Application::get_locale is currently unimplemented for X11 platforms. (defaulting to en-US)"); - "en-US".into() + let var_non_empty = |var| match std::env::var(var) { + Ok(s) if s.is_empty() => None, + Ok(s) => Some(s), + Err(_) => None, + }; + + // from gettext manual + // https://www.gnu.org/software/gettext/manual/html_node/Locale-Environment-Variables.html#Locale-Environment-Variables + var_non_empty("LANGUAGE") + // the LANGUAGE value is priority list seperated by : + // See: https://www.gnu.org/software/gettext/manual/html_node/The-LANGUAGE-variable.html#The-LANGUAGE-variable + .and_then(|locale| locale.split(':').next().map(String::from)) + .or_else(|| var_non_empty("LC_ALL")) + .or_else(|| var_non_empty("LC_MESSAGES")) + .or_else(|| var_non_empty("LANG")) + .unwrap_or_else(|| "en-US".to_string()) } pub(crate) fn idle_pipe(&self) -> RawFd {