loon-embed

Crates.ioloon-embed
lib.rsloon-embed
version0.5.0
sourcesrc
created_at2021-11-26 12:12:59.861654
updated_at2021-11-30 11:14:15.387858
descriptionI18n for Rust, support embed YAML, JSON.
homepage
repositoryhttps://github.com/longbridgeapp/loon
max_upload_size
id488002
size22,994
Jason Lee (huacnlee)

documentation

README

Loon

CI Docs Crates.io

Loon is a localization/internationalization library, inspired by ruby-i18n.

It use rust-embed for embed the localization assets into your binary.

Usage

Load locales assets by RustEmbed and init Loon in your lib.rs

use rust_embed::RustEmbed;

// Load Loon macro, for allow you use `t!` macro in anywhere.
#[macro_use]
extern crate loon_embed;

// Use RustEmbed to locale assets
#[derive(RustEmbed)]
#[folder = "locales/"]
#[include = "*.yml"]
struct Asset;

fn main() {
    loon_embed::init::<Asset>("en");
}

You must put I18n YAML files in locales/ folder.

locales/
├── en.yml
├── zh-CN.yml

For example of en.yml:

greeting: Hello world
messages:
  hello: Hello, {}

Now you can use t! macro in anywhere.

t!("greeting");
// => "Hello world"

t!("messages.hello", "world");
// => "Hello, world"

You can use loon_embed::set_locale or call loon_embed::init agian to change the current locale in runtime.

loon_embed::set_locale("zh-CN");
loon_embed::locale();
// => "zh-CN"

License

MIT

Commit count: 0

cargo fmt