A crate to help you internationalize your Rocket applications.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
asonix 3eca920593 Fix docs il y a 1 an
src Fix docs il y a 1 an
.gitignore Initial commit il y a 2 ans
.travis.yml Modify all link to match new repository location il y a 2 ans
Cargo.toml Upgrade actix, gettext il y a 1 an
LICENSE Add metadata + document the crate il y a 2 ans
README.md Merge branch 'master' of github.com:BaptisteGelez/rocket_i18n il y a 2 ans
rust-toolchain Upgrade actix, gettext il y a 1 an


Rocket I18N Build Status

A crate to help you internationalize your Rocket or Actix Web applications.

It just selects the correct locale for each request, and return the corresponding gettext::Catalog.


First add it to your Cargo.toml:

rocket_i18n = "0.4"
gettext-macros = "0.1" # Provides proc-macros to manage translations

Then, in your main.rs:

# use rocket;
use gettext_macros::{compile_i18n, include_i18n, init_i18n};

init_i18n!("my_web_app", en, eo, it, pl);

fn main() {
        // Make Rocket manage your translations.
        // Register routes, etc


Then in all your requests you’ll be able to use the i18n macro to translate anything. It takes a gettext::Catalog and a string to translate as argument.

use gettext_macros::i18n;
use rocket_i18n::I18n;

fn route(i18n: I18n) -> &str {
    i18n!(i18n.catalog, "Hello, world!")

For strings that may have a plural form, just add the plural and the number of element to the arguments

i18n!(i18n.catalog, "One new message", "{0} new messages", 42);

Any extra argument, after a ;, will be used for formatting.

let user_name = "Alex";
i18n!(i18n.catalog, "Hello {0}!"; user_name);

When using it with plural, {0} will be the number of elements, and other arguments will start at {1}.

Because of its design, rocket_i18n is only compatible with askama, ructe or compiled templates in general. You can use the t macro in your templates, as long as they have a field called catalog to store your catalog.

Using with Actix Web

First, disable the default features so it doesn’t pull in all of Rocket.

version = "0.4"
default-features = false
features = ["actix-web"]

Then add it to your application.

use gettext_macros::*;
use rocket_i18n::{I18n, Internationalized, Translations};

fn route_handler(i18n: I18n) -> &str {
    i18n!(i18n.catalog, "Hello, world!")

struct MyState {
    translations: Translations,

impl Internationalized for MyState {
    fn get(&self) -> Translations {

fn main() {
    let state = MyState {
        translations: rocket_i18n::i18n("your-domain", vec![ "en", "fr", "de", "ja" ]);

        .resource("", |r| r.with(route_handler))