This is a library for getting text from JSON usually for internationalization.
```rust
let ctx = staticjsongettextbuild!( "enUS", "enUS", "langs/enUS.json", "zhTW", "langs/zhTW.json" ).unwrap();
asserteq!("Hello, world!", gettext!(ctx, "hello").unwrap()); asserteq!("哈囉,世界!", gettext!(ctx, "zh_TW", "hello").unwrap()); ```
This crate supports the Rocket framework. In order to reload changed json files instead of recompiling the program you have to enable the rocketly
feature for this crate.
toml
[dependencies.json-gettext]
version = "*"
features = ["rocketly"]
Then, use the static_json_gettext_build_rocketly
macro instead of the static_json_gettext_build
macro to build a JSONGetText
(JSONGetTextManager
).
```rust
use rocket::State; use rocket::response::Redirect;
use json_gettext::JSONGetTextManager;
fn index(ctx: State
fn hello(ctx: State
fn main() { rocket::ignite() .attach(JSONGetTextManager::fairing(|| { staticjsongettextbuildrocketly!("enUS", "enUS", "langs/enUS.json", "zhTW", "langs/zh_TW.json" ) })) .mount("/", routes![index, hello]) .launch(); } ```
If you are not using the release
profile, JSONGetTextManager
can reload the json files automatically if needed.
https://crates.io/crates/json-gettext
https://docs.rs/json-gettext