i18nify
简体中文| English
Internationalization library for Rust based on code generation.
The original repository https://github.com/davidpdrsn/i18n_codegen was implemented by David Pedersen. However, it has some outdated dependencies and has not been maintained for as long as five years.
By leveraging code generation we are able to prevent common bugs like typos in i18n keys, missing interpolations, or various mistakes between locales.
Adding
or add Cargo.toml:
Usage
It requires a directory (based on CARGO_MANIFEST_DIR) with one JSON file per locale. Here is an example with English and
Danish translations:
// tests/doc_locales/en.json
// tests/doc_locales/da.json
And in Rust:
In Rust :
use Internationalize;
Allow environment variables to be used in the folder path. Example:
In Rust :
use Internationalize;
Using in the Axum Framework
First, define an Internationalization trait implementation
use ;
;
Then add the middleware I18nifyLayer:
let app = new
.route
.layer;
Finally, you can use Locale to get internationalized text in your handler
async
You can find more details on https://docs.rs/i18nify.