Crates.io | rs-i18n |
lib.rs | rs-i18n |
version | 0.0.1 |
source | src |
created_at | 2024-01-07 11:44:11.668958 |
updated_at | 2024-01-07 11:44:11.668958 |
description | A lightweight and compact I18n library |
homepage | |
repository | https://github.com/Surrealism-All/rs-i18n |
max_upload_size | |
id | 1091721 |
size | 22,051 |
A lightweight and compact I18n library
cargo add rs-i18n
cargo add lazy_static
-- your project
|---- i18n
| |-- en_US.json
| |-- zh_CN.json
{
"HELLO":"hello",
"HAPPY":"satisfied",
"JOY":"good"
}
{
"HELLO":"你好",
"HAPPY":"开心",
"JOY":"欢快"
}
#[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"));
}
cargo add strum --feature derive
----or----
strum = { version = "0.25", features = ["derive"] }
#[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)));
}