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

fix: get_locale follows posix standard #1264

Merged
merged 2 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All notable changes to eww will be listed here, starting at changes since versio
- Fix values in the `EWW_NET` variable (By: mario-kr)
- Fix the gtk `expander` widget (By: ovalkonia)
- Fix wayland monitor names support (By: dragonnn)
- `get_locale` now follows POSIX standard for locale selection (By: mirhahn, w-lfchen)

### Features
- Add OnDemand support for focusable on wayland (By: GallowsDove)
Expand Down
14 changes: 6 additions & 8 deletions crates/eww_shared_util/src/locale.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use chrono::Locale;
use std::env::var;

/// Returns the `Locale` enum based on the `LC_TIME` environment variable.
/// Returns the `Locale` enum based on the `LC_ALL`, `LC_TIME`, and `LANG` environment variables in
/// that order, which is the precedence order prescribed by Section 8.2 of POSIX.1-2017.
/// If the environment variable is not defined or is malformed use the POSIX locale.
pub fn get_locale() -> Locale {
let locale_string: String =
var("LC_TIME").map_or_else(|_| "C".to_string(), |v| v.split(".").next().unwrap_or("C").to_string());

match (&*locale_string).try_into() {
Ok(x) => x,
Err(_) => Locale::POSIX,
}
var("LC_ALL")
.or_else(|_| var("LC_TIME"))
.or_else(|_| var("LANG"))
.map_or(Locale::POSIX, |v| v.split('.').next().and_then(|x| x.try_into().ok()).unwrap_or_default())
}