Skip to content

Commit

Permalink
X11 shell locale detection (#1756)
Browse files Browse the repository at this point in the history
  • Loading branch information
maan2003 authored May 4, 2021
1 parent 99a8d66 commit 8e83610
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,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

Expand Down Expand Up @@ -710,6 +711,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
Expand Down
19 changes: 16 additions & 3 deletions druid-shell/src/platform/x11/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8e83610

Please sign in to comment.