diff --git a/Cargo.lock b/Cargo.lock index 44df435..f2bccaf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -798,7 +798,7 @@ checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] name = "salvo-cli" -version = "0.1.17" +version = "0.1.18" dependencies = [ "ansi_term", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index 3bb2232..7d9d57f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "salvo-cli" -version = "0.1.17" +version = "0.1.18" edition = "2021" authors = ["Fankai Liu liufankai137@outlook.com"] keywords = ["salvo", "cli","template"] diff --git a/src/i18n.rs b/src/i18n.rs index 4cae160..7d3e98d 100644 --- a/src/i18n.rs +++ b/src/i18n.rs @@ -1,8 +1,3 @@ -const SUPPORTED_LANGUAGES: [&str; 17] = [ - "en", "zh_CN", "zh_TW", "fr", "ja", "es", "de", "ru", - "it", "pt", "ko", "no", "is", "uk", "th", "el", "da" -]; - pub fn set_locale() { match get_language() { Some(lang) => { @@ -13,17 +8,12 @@ pub fn set_locale() { } } } - fn get_language() -> Option { match std::env::var("LANG") { Ok(lang) => { - let language = lang.split('.').next()?.to_string(); - if SUPPORTED_LANGUAGES.contains(&language.as_str()) { - Some(language) - } else { - None - } + let language = lang.split('.').next(); + language.map(|s| s.to_string()) } Err(_) => None, } -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index 0bf8643..6c3714d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,9 +4,9 @@ use clap::Parser; mod utils; use i18n::set_locale; mod i18n; -rust_i18n::i18n!("locales"); +rust_i18n::i18n!("locales", fallback = "en"); #[derive(Parser, Debug)] -#[clap(version = "0.1.17", author = "Fankai liu ")] +#[clap(version = "0.1.18", author = "Fankai liu ")] struct Opts { #[clap(subcommand)] subcmd: SubCommand,