4 releases

0.1.3 Dec 29, 2023
0.1.2 Dec 29, 2023
0.1.1 Dec 28, 2023
0.1.0 Dec 28, 2023

#145 in Internationalization (i18n)


Used in poise-i18n

MIT license

10KB
178 lines

Rusty18n

A pretty simple yet robust library to deal with i18n on Rust.

Why Rusty18n?

Wouldn't it be pretty useful and handy if you could write all your translations directly in your source code? This is what this crate is solving. I was in need of a simple and easy to use i18n solution for my discord bot, and I had the idea to create a simple in-memory i18n handler. It provides all the basis for what you would expect for an in-memory i18n in Rust, covering simple static translations to dynamic ones.

So how do i start?

You just need to do add some dependencies to your project:

cargo add rusty18n
cargo add deep_struct_update

deep_struct_update is used so you can write partial i18n implementations for languages that are still being working on, like in the example:

// We need to import deep_struct_update before we can use the define_i18n macro
use deep_struct_update;

pub fn i18n_ptbr() -> I18NUsage {
    // Using the define_i18n macro we don't need to change all the i18n implementations once
    // something in the base fallback implementation structure changes.
    define_i18n! {
        I18NUsage,
        greetings: {
            waves: r!("Oi!"),
        }
    }
}

You can see an example usage here

Dependencies

~5–7.5MB
~141K SLoC