locales: introduce Internationalization / Locales

* using crate locales

Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
2019-10-31 00:58:00 +01:00
parent d5f58f2576
commit 0a9fdbab2a
3 changed files with 29 additions and 2 deletions

View File

@@ -23,3 +23,6 @@ features = [ "postgres", "sqlite" ]
[dependencies.dotenv] [dependencies.dotenv]
version = "0.10.0" version = "0.10.0"
[dependencies.locales]
version = "0.1.0"

15
locales/main.json Normal file
View File

@@ -0,0 +1,15 @@
{
"err.user.not_found": {
"fr": "Utilisateur introuvable: $email, $id",
"de": "Anwender nicht gefunden: $email, $id",
"en": "User not found: $email, $id"
},
"main.start": {
"de": "Programmlogik starten",
"en": "Starting program logic"
},
"parse.arguments": {
"de": "Programmargumente prüfen",
"en": "Parsing arguments"
}
}

View File

@@ -1,12 +1,21 @@
#[macro_use] #[macro_use]
extern crate clap; extern crate clap;
extern crate locales;
use clap::App; use clap::App;
use locales::t;
fn main() { fn main() {
println!("Parsing arguments ..."); // set locale
let lang= "de";
// handle commandline arguments with clap (relative path to cli.yml) // handle commandline arguments with clap (relative path to cli.yml)
let res = t!("parse.arguments", lang);
println!("{}", &res);
let yaml = load_yaml!("cli.yml"); let yaml = load_yaml!("cli.yml");
let _matches = App::from_yaml(yaml).get_matches(); let _matches = App::from_yaml(yaml).get_matches();
println!("Starting program logic ..."); let res = t!("main.start", lang);
println!("{}", &res);
} }