i18nx

Crates.ioi18nx
lib.rsi18nx
version0.1.0
sourcesrc
created_at2022-12-02 06:11:32.358073
updated_at2022-12-02 06:11:32.358073
descriptionElegant internationalization library for Rust.
homepage
repositoryhttps://github.com/ivanstepanovftw/i18nx
max_upload_size
id728130
size28,339
Ivan Stepanov (ivanstepanovftw)

documentation

https://docs.rs/i18nx

README

i18nx

i18nx is a runtime localization library for Rust. It is designed to be simple and easy to use.

It supports Rusty Object Notation (RON) files for translation data. Refer to the RON documentation for more information.

It exports a single macro t! that can be used to translate strings at runtime.

For formatting, it uses the same syntax as the format! macro. Refer to the formatx documentation for more information.

Usage

use i18nx::t;

// Create a new translation dictionary
// Tip: use `include_str` macro to embed translation files
i18nx::from_ron!(r#"{
  "Hello {name}!": {
    "de": "Hallo {name}!",
    "fr": "Bonjour {name}!",
  },
}"#);

// If you prefer storing your localizations separately
i18nx::with_ron!("cn", r#"{
  "Hello {name}!": "你好 {name}!",
}"#);
i18nx::with_ron!("ru", r#"{
  "Hello {name}!": "Привет {name}!",
}"#);

// Set locale anytime
i18nx::locale!("fr");

// Use the `t` macro just like you would use `format`
assert_eq!(
    t!("Hello {name}!", name = "Rustaceans"),
    "Bonjour Rustaceans!"
);
assert_eq!(
    t!("No translation for this string, so it will be printed and formatted as-is."),
    "No translation for this string, so it will be printed and formatted as-is."
);

See also: integration example and integration test.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Commit count: 1

cargo fmt