1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//! # 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`:
//!
//! ```toml
//! [dependencies]
//! rocket_i18n = "0.4"
//! gettext-macros = "0.1" # Provides proc-macros to manage translations
//! ```
//!
//! Then, in your `main.rs`:
//!
//! ```rust,ignore
//! # use rocket;
//! use gettext_macros::{compile_i18n, include_i18n, init_i18n};
//!
//! init_i18n!("my_web_app", en, eo, it, pl);
//!
//! fn main() {
//! rocket::ignite()
//! // Make Rocket manage your translations.
//! .manage(include_i18n!());
//! // Register routes, etc
//! }
//!
//! 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.
//!
//! ```rust,ignore
//! use gettext_macros::i18n;
//! use rocket_i18n::I18n;
//!
//! #[get("/")]
//! 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
//!
//! ```rust,ignore
//! i18n!(i18n.catalog, "One new message", "{0} new messages", 42);
//! ```
//!
//! Any extra argument, after a `;`, will be used for formatting.
//!
//! ```rust,ignore
//! 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.
extern crate actix_web;
extern crate gettext;
extern crate rocket;
pub use *;
use fs;
pub use Internationalized;
const ACCEPT_LANG: &'static str = "Accept-Language";
/// A request guard to get the right translation catalog for the current request.
pub type Translations = ;
/// Loads translations at runtime. Usually used with `rocket::Rocket::manage`.
///
/// Note that the `.mo` files should be present with your binary. If you want to embed them,
/// use `gettext_macros::include_i18n`.
/// Works the same way as `gettext_macros::i18n`, but without needing to give a `gettext::Catalog`
/// as first argument.
///
/// For use in askama templates.