1use rust_i18n::{self};
2
3pub fn init() {
4 let preferred = vec![
6 std::env::var("RUST_I18N_LOCALE").ok(),
8 std::env::var("LANG").ok(),
9 std::env::var("LC_ALL").ok(),
10 sys_locale::get_locale(),
12 Some("en".to_string()),
14 ];
15
16 let mut locale = "en".to_string();
17
18 for loc in preferred.into_iter().flatten() {
19 let loc = loc
20 .split('.')
21 .next()
22 .unwrap()
23 .replace('_', "-")
24 .to_lowercase();
25
26 if rust_i18n::available_locales!().contains(&loc.as_str()) {
27 locale = loc;
29 break;
30 }
31
32 if let Some(short) = loc.split('-').next() {
33 if rust_i18n::available_locales!().contains(&short) {
35 locale = short.to_string();
36 break;
37 }
38 }
39 }
40
41 log::debug!("locale: {}", locale); rust_i18n::set_locale(&locale);
44 }