Add new macro importing translation to the final binary

Add a new macro include_i18n!, taking similar arguments to i18n(),
and expanding to the same type. It allow to include translations in
the final binary, so that once compiled, it can be run from anywhere,
without depending on `.mo`s to be present
pull/12/head
Trinity Pointard 5 years ago
parent 4148b79c18
commit 6acd7c7be6

@ -124,6 +124,27 @@ pub fn i18n(domain: &str, lang: Vec<&'static str>) -> Translations {
})
}
#[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};

Loading…
Cancel
Save