4 releases

✓ Uses Rust 2018 edition

0.0.3 Oct 9, 2019
0.0.2 Oct 9, 2019
0.0.1 Oct 3, 2019
0.0.0 Oct 3, 2019

#69 in Internationalization (i18n)

Download history 8/week @ 2019-11-01 1/week @ 2019-11-08 17/week @ 2019-11-15 4/week @ 2019-11-22 9/week @ 2019-11-29 23/week @ 2019-12-06 73/week @ 2019-12-13 4/week @ 2019-12-27 2/week @ 2020-01-03 70/week @ 2020-01-10 9/week @ 2020-01-17 5/week @ 2020-02-07

89 downloads per month


167 lines


LICENSE Crates.io Version Coverage Status Build Status

An simple compile time i18n implementation in Rust. It throws a compilation error if the translation key is not present, but since the lang argument is dynamic it will panic if the language has not been added for the matching key.

API documentation https://crates.io/crates/internationalization


Have a locales/ folder somewhere in your app, root, src, anywhere. with .json files, nested in folders or not. It uses a glob pattern: **/locales/**/*.json to match your translation files.

the files must look like this:

  "err.user.not_found": {
    "fr": "Utilisateur introuvable: $email, $id",
    "en": "User not found: $email, $id"
  "err.answer.all": {
    "fr": "Échec lors de la récupération des réponses",
    "en": "Failed to retrieve answers"
  "err.answer.delete.failed": {
    "fr": "Échec lors de la suppression de la réponse",
    "en": "Failed to delete answer"

Any number of languages can be added, but you should provide them for everything since it will panic if a language is not found when queried for a key.

In your app, jsut call the t! macro

fn main() {
    let lang = "en";
    let res = t!("err.not_allowed", lang);

    assert_eq!("You are not allowed to do this", res);

You can use interpolation, any number of argument is OK but you should note that they have to be sorted alphabetically. To use variables, call the t! macro like this:

fn main() {
    let lang = "en";
    let res = t!("err.user.not_found", email: "me@localhost", id: "1", lang);

    assert_eq!("User not found: me@localhost, ID: 1", res);


Internationalization is available on crates.io, include it in your Cargo.toml:

internationalization = "0.0.2"

Then include it in your code like this:

extern crate internationalization;

Or use the macro where you want to use it:

use internationalization::t;


Internationalization will not work if no PWD env var is set at compile time.

No runtime deps