diff --git a/src/lib.rs b/src/lib.rs index c9429e1..46e7170 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -124,6 +124,36 @@ pub fn i18n(domain: &str, lang: Vec<&'static str>) -> Translations { }) } +/// Use this macro to staticaly import translations into your final binary. It's use is similar to +/// [`i18n`](../rocket_i18n/fn.i18n.html) +/// ```rust,ignore +/// # //ignore because there is no translation file provided with rocket_i18n +/// # #[macro_use] +/// # extern crate rocket_i18n; +/// # use rocket_i18n::Translations; +/// let tr: Translations = include_i18n!("plume", ["de", "en", "fr"]); +/// ``` +#[macro_export] +macro_rules! include_i18n { + ( $domain:tt, [$($lang:tt),*] ) => { + { + use $crate::Catalog; + vec![ + $( + ( + $lang, + Catalog::parse( + &include_bytes!( + concat!(env!("CARGO_MANIFEST_DIR"), "/translations/", $lang, "/LC_MESSAGES/", $domain, ".mo") + )[..] + ).expect("Error while loading catalog") + ) + ),* + ] + } + } +} + #[cfg(feature = "build")] pub fn update_po(domain: &str, locales: &[&'static str]) { use std::{path::Path, process::Command};