diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c49e09d1e..c7d12db5b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -111,6 +111,7 @@ You can find its changes [documented below](#070---2021-01-01). - Updated to x11rb 0.8.0. ([#1519] by [@psychon]) - Updated fluent-bundle to 0.15.1 and fluent syntax to 0.11.0 ([#1772] by [@r-ml]) - Updated usvg to 0.14.1 ([#1802] by [@r-ml]) +- x11: Add logging to `Application::get_locale` ([#1876] by [@Maan2003]) ### Outside News @@ -761,6 +762,7 @@ Last release without a changelog :( [#1867]: https://github.com/linebender/druid/pull/1867 [#1868]: https://github.com/linebender/druid/pull/1868 [#1873]: https://github.com/linebender/druid/pull/1873 +[#1876]: https://github.com/linebender/druid/pull/1876 [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/backend/x11/application.rs b/druid-shell/src/backend/x11/application.rs index bbf7e26d00..2cad86b49d 100644 --- a/druid-shell/src/backend/x11/application.rs +++ b/druid-shell/src/backend/x11/application.rs @@ -770,21 +770,36 @@ impl Application { } pub fn get_locale() -> String { - let var_non_empty = |var| match std::env::var(var) { - Ok(s) if s.is_empty() => None, - Ok(s) => Some(s), - Err(_) => None, - }; + fn locale_env_var(var: &str) -> Option { + match std::env::var(var) { + Ok(s) if s.is_empty() => { + tracing::debug!("locale: ignoring empty env var {}", var); + None + } + Ok(s) => { + tracing::debug!("locale: env var {} found: {:?}", var, &s); + Some(s) + } + Err(std::env::VarError::NotPresent) => { + tracing::debug!("locale: env var {} not found", var); + None + } + Err(std::env::VarError::NotUnicode(_)) => { + tracing::debug!("locale: ignoring invalid unicode env var {}", var); + None + } + } + } // from gettext manual // https://www.gnu.org/software/gettext/manual/html_node/Locale-Environment-Variables.html#Locale-Environment-Variables - let mut locale = var_non_empty("LANGUAGE") + let mut locale = locale_env_var("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")) + .or_else(|| locale_env_var("LC_ALL")) + .or_else(|| locale_env_var("LC_MESSAGES")) + .or_else(|| locale_env_var("LANG")) .unwrap_or_else(|| "en-US".to_string()); // This is done because the locale parsing library we use expects an unicode locale, but these vars have an ISO locale