9 releases

0.1.8 Jul 9, 2024
0.1.7 Jul 9, 2024
0.1.6 May 31, 2024
0.1.3 Dec 29, 2023

#89 in Internationalization (i18n)

Download history 25/week @ 2024-09-16 5/week @ 2024-09-23 17/week @ 2024-09-30

650 downloads per month
Used in poise-i18n

MIT license

13KB
205 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

~0–2.7MB
~47K SLoC