[−][src]Crate 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::*; 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::*; 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"]).
Modules
| err | Error management |
Structs
| Config | Configuration to build a |
| Count | Helper for setting |
| DefaultKey | Helper for setting |
| DefaultLocale | Helper for setting |
| Dictionary | Container for translation messages |
| Locale | Helper for setting |
| LocalizedPath | Helper for setting |
| Opts | Options (optional) for the |
| PathPattern | Helper for setting |
| Var | Helper for setting interpolated variables |
Functions
| set_config | Sets the |
| t | Shortcut for |
| translate | Get the translated message, using the global configuration. |