8 releases
0.3.4 | Mar 5, 2020 |
---|---|
0.3.3 | Mar 5, 2020 |
0.2.1 | Mar 3, 2020 |
0.1.0 | Mar 2, 2020 |
#243 in Internationalization (i18n)
23 downloads per month
26KB
571 lines
loon
lo[calizati]on
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.
Usage:
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!")
);
}
Features
Translation files can be:
- JSON
- YAML (enabled by default, disable with
default-features = false
), or - TOML (enable with
features = ["toml"]
).
Current version: 0.3.4
License: MIT
Dependencies
~0.8–2MB
~43K SLoC