macro_rules! t {
($($all:tt)*) => { ... };
}Expand description
Get I18n text
This macro forwards to the crate::_rust_i18n_t! macro, which is generated by the i18n! macro.
§Arguments
expr- The key or message for translation.- A key usually looks like
"foo.bar.baz". - A literal message usually looks like
"Hello, world!". - The variable names in the message should be wrapped in
%{}, like"Hello, %{name}!". - Dynamic messages are also supported, such as
t!(format!("Hello, {}!", name)). However, ifminify_keyis enabled, the entire message will be hashed and used as a key for every lookup, which may consume more CPU cycles.
- A key usually looks like
locale- The locale to use. If not specified, the current locale will be used.args- The arguments to be replaced in the translated text.- These should be passed in the format
key = valueorkey => value. - Alternatively, you can specify the value format using the
key = value : {:format_specifier}syntax. For example,key = value : {:08}will format the value as a zero-padded string with a length of 8.
- These should be passed in the format
§Example
#[macro_use] extern crate rust_i18n;
// Simple get text with current locale
t!("greeting");
// greeting: "Hello world" => "Hello world"
// Get a special locale's text
t!("greeting", locale = "de");
// greeting: "Hallo Welt!" => "Hallo Welt!"
// With variables
t!("messages.hello", name = "world");
// messages.hello: "Hello, %{name}" => "Hello, world"
t!("messages.foo", name = "Foo", other ="Bar");
// messages.foo: "Hello, %{name} and %{other}" => "Hello, Foo and Bar"
// With variables and format specifiers
t!("Hello, %{name}, you serial number is: %{sn}", name = "Jason", sn = 123 : {:08});
// => "Hello, Jason, you serial number is: 000000123"
// With locale and variables
t!("messages.hello", locale = "de", name = "Jason");
// messages.hello: "Hallo, %{name}" => "Hallo, Jason"