#internationalization #localization #translation #web

macro i18n_codegen

Safe localization library using code generation

2 releases

0.1.1 Sep 29, 2019
0.1.0 Sep 29, 2019

#45 in #i18n

Download history 54/week @ 2024-02-26 49/week @ 2024-03-04 37/week @ 2024-03-11 42/week @ 2024-03-18 54/week @ 2024-03-25 95/week @ 2024-04-01 78/week @ 2024-04-08 59/week @ 2024-04-15 67/week @ 2024-04-22 129/week @ 2024-04-29 93/week @ 2024-05-06 46/week @ 2024-05-13 39/week @ 2024-05-20 12/week @ 2024-05-27 23/week @ 2024-06-03 32/week @ 2024-06-10

122 downloads per month

MIT license

32KB
729 lines

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.

Dependencies

~4.5MB
~94K SLoC