Crates.io | loon |
lib.rs | loon |
version | 0.3.4 |
source | src |
created_at | 2020-03-02 18:16:00.686651 |
updated_at | 2020-03-05 17:25:55.616823 |
description | Simple localization |
homepage | |
repository | https://github.com/kardeiz/loon |
max_upload_size | |
id | 214550 |
size | 26,358 |
A very simple localization/internationalization library, inspired by ruby-i18n
.
Provides a (configurable) global translate
/t
function for convenience, as well
as a Dictionary
builder/container if you prefer to manage state directly.
Global function:
fn main() {
use loon::prelude::*;
loon::set_config(PathPattern("examples/locales/*.yml")).unwrap();
assert_eq!(
t("custom.greeting", Var("name", "Jacob")).unwrap(),
String::from("Hello, Jacob!!!")
);
assert_eq!(
t("greeting", Opts::default().locale("de")).unwrap(),
String::from("Hallo Welt!")
);
}
Using a Dictionary
:
fn main() {
use loon::prelude::*;
let dict = Config::default()
.with_path_pattern("examples/locales/*.yml")
.finish()
.unwrap();
assert_eq!(
dict.translate("custom.greeting", Var("name", "Jacob")).unwrap(),
String::from("Hello, Jacob!!!")
);
assert_eq!(
dict.translate("greeting", Opts::default().locale("de")).unwrap(),
String::from("Hallo Welt!")
);
}
Translation files can be:
default-features = false
), orfeatures = ["toml"]
).Current version: 0.3.4
License: MIT