Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X11 shell locale detection #1756

Merged
merged 3 commits into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ You can find its changes [documented below](#070---2021-01-01).
- Fixed layout of scrollbar with very small viewports ([#1715] by [@andrewhickman])
- Fixed `WindowLevel::Tooltip` on Windows platform ([#1737] by [@djeedai])
- X11 backend now supports scaling([#1751] by [@Maan2003])
- X11 backend now uses the platform locale ([#1756] by [@Maan2003])

### Visual

Expand Down Expand Up @@ -701,6 +702,7 @@ Last release without a changelog :(
[#1737]: https://github.com/linebender/druid/pull/1737
[#1743]: https://github.com/linebender/druid/pull/1743
[#1751]: https://github.com/linebender/druid/pull/1751
[#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 @@ -495,9 +495,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")
.or_else(|| var_non_empty("LC_ALL"))
.or_else(|| var_non_empty("LC_MESSAGES"))
.or_else(|| var_non_empty("LANG"))
// the value is priority list seperated by :
// See: https://www.gnu.org/software/gettext/manual/html_node/The-LANGUAGE-variable.html#The-LANGUAGE-variable
maan2003 marked this conversation as resolved.
Show resolved Hide resolved
.and_then(|locale| locale.split(':').next().map(String::from))
.unwrap_or_else(|| "en-US".to_string())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a difference between "en-US" and "en_US"? My system uses the latter...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better idea to en_US. I used en-US because it was used in the stub earlier.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The identifiers can vary in case and in the separator characters. The "-" and "_" separators are treated as equivalent, although "-" is preferred.

(from Unicode TR #35)

}

pub(crate) fn idle_pipe(&self) -> RawFd {
Expand Down