#translation #compile-time

tiny-i18n

A tiny library to internationalize your project

12 releases

0.1.12 Aug 10, 2024
0.1.11 Aug 10, 2024
0.1.9 Jul 21, 2024
0.1.6 Jun 6, 2024

#92 in Internationalization (i18n)

Download history 2/week @ 2024-06-29 8/week @ 2024-07-06 12/week @ 2024-07-13 307/week @ 2024-07-20 50/week @ 2024-07-27 3/week @ 2024-08-03 220/week @ 2024-08-10 7/week @ 2024-08-17 26/week @ 2024-09-14 35/week @ 2024-09-28

61 downloads per month

Custom license

5KB

My i18n Rust library

Features

  • Fully at compile-time (shouldn't ever crash or experience an issue at runtime, any crash or issue at runtime should be reported as an issue)
  • [x] Supports arguments (not named, it uses format!() under the hood, see its documentation for all of its caracteristics)
  • Supports named arguments (of the form $argument_name)
  • Fallback language choice (for now, it is always en-US)

Example

///This macro generates a function per translation key inside the specified struct.
#[tiny_i18n::i18n("path_of_the_translations_directory")] //defaults to `i18n` if called without argument
pub(crate) struct I18n;

fn main() {
    // Each translation key generates a function (every non-ASCII letter, number or underscore are removed)
    println!("{}", I18n::hello_world("en-us")); //the first argument is the language, the following are the arguments, if any
}

The structure is the following :

└── *The name of your i18n folder*
    └── en-US
        └── *You can put as many files as you want (with any/no extension) inside each language folder (or inside any subfolder (as many subfolders as you want)), the name of the file (without the extension) is the id of the translation*
    └── *Other languages*

Dependencies

~230–670KB
~16K SLoC