Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the rust-i18n crate to ructe-based templates. #340

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions aardwolf-localization/src/lib.rs
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
7 changes: 6 additions & 1 deletion aardwolf-templates/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ path = "../aardwolf-models"
version = "0.1.0"
path = "../aardwolf-yew-frontend"

#-
# Adding rust-i18n for handling localization
[dependencies]
rust-i18n = "3"

#-
# Adding syn for template compilation
[dependencies.syn]
version = "2.0.77"
features = ["full", "extra-traits"]
features = ["full", "extra-traits"]
Loading