JSON Get Text

Build Status

This is a library for getting text from JSON usually for internationalization.

Example

```rust

[macrouse] extern crate jsongettext;

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()); ```

Rocket Support

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

[macrouse] extern crate jsongettext;

[macro_use] extern crate rocket;

use rocket::State; use rocket::response::Redirect;

use json_gettext::JSONGetTextManager;

[get("/")]

fn index(ctx: State) -> Redirect { Redirect::temporary(uri!(hello: lang = ctx.getdefaultkey())) }

[get("/")]

fn hello(ctx: State, lang: String) -> String { format!("Ron: {}", gettext!(ctx, lang, "hello").unwrap().asstr().unwrap()) }

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.

Crates.io

https://crates.io/crates/json-gettext

Documentation

https://docs.rs/json-gettext

License

MIT