Internationalization
An simple compile time i18n implementation in Rust.
It throws a compilation error if the translation key is not present, but since the lang
argument is dynamic it will panic if the language has not been added for the matching key.
API documentation https://crates.io/crates/internationalization
Usage
Have a locales/
folder somewhere in your app, root, src, anywhere. with .json
files, nested in folders or not.
It uses a glob pattern: **/locales/**/*.json
to match your translation files.
the files must look like this:
Any number of languages can be added, but you should provide them for everything since it will panic if a language is not found when queried for a key.
In your app, jsut call the t!
macro
You can use interpolation, any number of argument is OK but you should note that they have to be sorted alphabetically.
To use variables, call the t!
macro like this:
Installation
Internationalization is available on crates.io, include it in your Cargo.toml
:
[]
= "0.0.2"
Then include it in your code like this:
extern crate internationalization;
Or use the macro where you want to use it:
use t;
Note
Internationalization will not work if no PWD
env var is set at compile time.