rs-i18n 0.0.1

A lightweight and compact I18n library
Documentation
  • Coverage
  • 98.39%
    61 out of 62 items documented0 out of 0 items with examples
  • Size
  • Source code size: 24.2 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.59 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 22s Average build duration of successful builds.
  • all releases: 22s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Surrealism-All/rs-i18n
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • syf20020816

rs-i18n

A lightweight and compact I18n library

QuickStart

1. install dependencies

cargo add rs-i18n

cargo add lazy_static

2. write i18n json file

-- your project

|---- i18n

|       |-- en_US.json

|       |-- zh_CN.json

en_US.json

{
  "HELLO":"hello",
  "HAPPY":"satisfied",
  "JOY":"good"
}

zh_CN.json

{
  "HELLO":"你好",
  "HAPPY":"开心",
  "JOY":"欢快"
}

3. main.rs

#[macro_use]
extern crate lazy_static;

use rs_i18n::{I18ns, Loader, UseI18n};

// if use absolute path, you should pay attention that the path should write from root
// means :
// It is an absolute path based on the root directory as the standard
lazy_static! {
    static ref LOADER: Loader = Loader::new(Some("./i18n"));
}

fn main() {
    let mut i18n = UseI18n::new(
        &LOADER,
        None,
    );
    // change lang
    // i18n.set_lang(I18ns::ENUS);
    println!("{}", i18n.t("JOY"));
}

Use Dev (recommend)

add strum

cargo add strum --feature derive

----or----

strum = { version = "0.25", features = ["derive"] }

main.rs

#[macro_use]
extern crate lazy_static;

use rs_i18n::{I18ns, Loader, UseI18n};
mod i18n_dict;

use i18n_dict::I18nDict;

lazy_static! {
    static ref LOADER: Loader = Loader::new(Some("./i18n"));
}
fn main() {
    // donot use absoulte path
    let mut i18n = UseI18n::new(
        &LOADER,
        Some("E:\\Rust\\try\\rs-i18n-all\\i18n-test\\src\\i18n_dict.rs"),
    );
    println!("{}", i18n.t(&format!("{:?}", I18nDict::HAPPY)));
}

Goals

  • translate
  • get system lang as default
  • dev
  • date format