internationalization/
lib.rs

1#![no_std]
2
3extern crate alloc;
4
5#[cfg(feature = "std")]
6extern crate std;
7
8mod range;
9
10pub use range::*;
11
12pub use internationalization_macros::translate;
13
14const DEFAULT_LOCALE: &str = "en";
15const DEFAULT_FALLBACK_LOCALE: &str = "en";
16
17pub const fn get_locale() -> &'static str {
18    match option_env!("INTERNATIONALIZATION_LOCALE") {
19        Some(locale) => locale,
20        None => DEFAULT_LOCALE,
21    }
22}
23
24pub const fn get_fallback_locale() -> &'static str {
25    match option_env!("INTERNATIONALIZATION_FALLBACK") {
26        Some(locale) => locale,
27        None => DEFAULT_FALLBACK_LOCALE,
28    }
29}
30
31#[cfg(feature = "std")]
32pub fn get_locale_build() -> std::string::String {
33    use std::string::ToString;
34
35    match std::env::var("INTERNATIONALIZATION_LOCALE") {
36        Ok(locale) => locale,
37        Err(_) => DEFAULT_LOCALE.to_string(),
38    }
39}
40
41#[cfg(feature = "std")]
42pub fn get_fallback_locale_build() -> std::string::String {
43    use std::string::ToString;
44
45    match std::env::var("INTERNATIONALIZATION_FALLBACK") {
46        Ok(locale) => locale,
47        Err(_) => DEFAULT_FALLBACK_LOCALE.to_string(),
48    }
49}