-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the
rust-i18n
crate to ructe-based templates. (#340)
- Loading branch information
Showing
2 changed files
with
41 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,41 @@ | ||
// Load macro and init translations. | ||
// https://crates.io/crates/rust-i18n | ||
|
||
///- | ||
// Start of rust-i18n configuration | ||
// Load I18n macro, for allow you use `t!` macro in anywhere. | ||
#[macro_use] | ||
extern crate rust_i18n; | ||
|
||
// Init translations for current crate. | ||
// This will load Configuration using the `[package.metadata.i18n]` section in `Cargo.toml` if exists. | ||
// Or you can pass arguments by `i18n!` to override it. | ||
i18n!("locales"); | ||
|
||
// Config fallback missing translations to "en" locale. | ||
// Use `fallback` option to set fallback locale. | ||
i18n!("locales", fallback = "en-us"); | ||
// | ||
i18n!("locales", fallback = "en"); | ||
|
||
// Or more than one fallback with priority. | ||
// | ||
i18n!("locales", fallback = ["en", "es"]); | ||
|
||
// Use a short hashed key as an identifier for long string literals | ||
// to optimize memory usage and lookup speed. | ||
// The key generation algorithm is `${Prefix}${Base62(SipHash13("msg"))}`. | ||
i18n!("locales", minify_key = true); | ||
// | ||
// Alternatively, you can customize the key length, prefix, | ||
// and threshold for the short hashed key. | ||
i18n!("locales", | ||
minify_key = true, | ||
minify_key_len = 12, | ||
minify_key_prefix = "t_", | ||
minify_key_thresh = 64 | ||
); | ||
// Now, if the message length exceeds 64, the `t!` macro will automatically generate | ||
// a 12-byte short hashed key with a "t_" prefix for it, if not, it will use the original. | ||
|
||
// If no any argument, use config from Cargo.toml or default. | ||
i18n!(); | ||
|
||
// End rust-i18n configuration | ||
///S |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters