A crate to help you internationalize your Rocket applications.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
asonix 3eca920593 Fix docs pirms 1 gada
src Fix docs pirms 1 gada
.gitignore Initial commit pirms 2 gadiem
.travis.yml Modify all link to match new repository location pirms 2 gadiem
Cargo.toml Upgrade actix, gettext pirms 1 gada
LICENSE Add metadata + document the crate pirms 2 gadiem
README.md Merge branch 'master' of github.com:BaptisteGelez/rocket_i18n pirms 2 gadiem
rust-toolchain Upgrade actix, gettext pirms 1 gada


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))