Skip to content
i18n library for Rust with compile time checks
Rust
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Bump to version 0.1.1 Sep 29, 2019
tests Error if keys are missing from some locales Sep 29, 2019
.gitignore Initial working spike Feb 2, 2019
CHANGELOG.md Bump to version 0.1.1 Sep 29, 2019
Cargo.toml Bump to version 0.1.1 Sep 29, 2019
LICENSE Release version 0.1.0 Sep 29, 2019
README.md Release version 0.1.0 Sep 29, 2019

README.md

i18n_codegen

Internationalization library for Rust based on code generation.

By leveraging code generation we are able to prevent common bugs like typos in i18n keys, missing interpolations, or various mistakes between locales.

It requires a directory with one JSON file per locale. Here is an example with English and Danish translations:

// tests/doc_locales/en.json
{
    "hello_world": "Hello, World!",
    "greeting": "Hello {name}"
}

// tests/doc_locales/da.json
{
    "hello_world": "Hej, Verden!",
    "greeting": "Hej {name}"
}

And in Rust:

use i18n_codegen::i18n;

i18n!("tests/doc_locales");

fn main() {
    assert_eq!("Hello, World!", Locale::En.hello_world());
    assert_eq!("Hej, Verden!", Locale::Da.hello_world());

    assert_eq!("Hello Bob", Locale::En.greeting(Name("Bob")));
    assert_eq!("Hej Bob", Locale::Da.greeting(Name("Bob")));
}

You can find more details on https://docs.rs/i18n_codegen.

You can’t perform that action at this time.