Rocket I18N
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
.
Usage
First add it to your Cargo.toml
:
[]
= "0.4"
= "0.1" # Provides proc-macros to manage translations
Then, in your main.rs
:
# use rocket;
use ;
init_i18n!;
compile_i18n!;
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 i18n;
use I18n;
For a detailed explanation about i18n!
, see its documentation.
You can also use the t
macro in your templates, as long as they have a field called catalog
to
store your catalog. This is especially useful for Askama templates.
Using with Actix Web
First, disable the default features so it doesn't pull in all of Rocket.
[]
= "0.4"
= false
= ["actix-web"]
Then add it to your application.
use *;
use ;