i18n-embed crates.io badge docs.rs badge license badge github actions badge

This library contains traits and macros to conveniently embed the output of cargo-i18n into your application binary in order to localize it at runtime.

Currently this library depends on rust-embed to perform the actual embedding of the language files. This may change in the future to make the library more convenient to use.

Changelog

Optional Features

The i18n-embed crate has the following optional Cargo features:

Example

The following is an example for how to derive the required traits on structs, and localize your binary using this library:

```rust use i18nembed::{I18nEmbed, languageloader, DesktopLanguageRequester}; use rust_embed::RustEmbed;

[derive(RustEmbed, I18nEmbed)]

[folder = "i18n/mo"] // path to the compiled localization resources

struct Translations;

language_loader!(MyLanguageLoader);

fn main() { let translations = Translations {}; let language_loader = MyLanguageLoader::new();

// Use the language requester for the desktop platform (linux, windows, mac).
// There is also a requester available for the web-sys WASM platform called
// WebLanguageRequester, or you can implement your own.
let requested_languages = DesktopLanguageRequester::requested_languages();

i18n_embed::select(&language_loader, &translations, &requested_languages);

} ```

For more examples, see the documentation for i18n-embed.