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