diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2018-12-25 18:37:20 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2018-12-25 18:37:20 +0100 |
commit | 0b4137250233bbe68ee5d76550edaa15a20a370e (patch) | |
tree | 02d16c6964a8d0061166ab36aa7d702d6032ce74 /src | |
parent | ebe4d4244c7cf716229d34c84def32742859d988 (diff) | |
download | primstav-0b4137250233bbe68ee5d76550edaa15a20a370e.tar.gz primstav-0b4137250233bbe68ee5d76550edaa15a20a370e.tar.bz2 primstav-0b4137250233bbe68ee5d76550edaa15a20a370e.zip |
Fetch locale from program environment.
Diffstat (limited to 'src')
-rw-r--r-- | src/locale.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/locale.rs b/src/locale.rs index 1bd190b..7d4b940 100644 --- a/src/locale.rs +++ b/src/locale.rs @@ -33,8 +33,20 @@ impl Locale { } } +fn from_locale_str(l: &str) -> &'static Locale { + match &l[0..2] { + "nb" => &NB, + _ => &EN, // Return default EN locale if we don't have a locale for the given str. + } +} + pub fn get() -> &'static Locale { - &EN + match std::env::var("LC_TIME") { + Ok(l) => { + from_locale_str(&l) + }, + Err(_) => &EN, // Return default EN locale if no locale is defined + } } pub const EN: Locale = Locale { |