Skip to content

Commit

Permalink
use rust-i18n fallbake
Browse files Browse the repository at this point in the history
  • Loading branch information
fankaiLiu committed Nov 7, 2023
1 parent 9db4e93 commit 4b71777
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "salvo-cli"
version = "0.1.17"
version = "0.1.18"
edition = "2021"
authors = ["Fankai Liu [email protected]"]
keywords = ["salvo", "cli","template"]
Expand Down
16 changes: 3 additions & 13 deletions src/i18n.rs
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -13,17 +8,12 @@ pub fn set_locale() {
}
}
}

fn get_language() -> Option<String> {
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,
}
}
}
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>")]
#[clap(version = "0.1.18", author = "Fankai liu <[email protected]>")]
struct Opts {
#[clap(subcommand)]
subcmd: SubCommand,
Expand Down

0 comments on commit 4b71777

Please sign in to comment.