1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
pub mod error;
pub mod gettext_impl;
pub mod util;
pub mod watch;
use anyhow::Result;
use i18n_config;
#[cfg(feature = "localize")]
use i18n_embed::{DefaultLocalizer, I18nEmbed, LanguageLoader, Localizer};
#[cfg(feature = "localize")]
use rust_embed::RustEmbed;
#[cfg(feature = "localize")]
#[derive(RustEmbed, I18nEmbed)]
#[folder = "i18n/mo"]
struct Translations;
#[cfg(feature = "localize")]
#[derive(LanguageLoader)]
struct I18nBuildLanguageLoader;
#[cfg(feature = "localize")]
const LANGUAGE_LOADER: I18nBuildLanguageLoader = I18nBuildLanguageLoader {};
#[cfg(feature = "localize")]
const TRANSLATIONS: Translations = Translations {};
pub fn run(crt: &i18n_config::Crate) -> Result<()> {
let i18n_config = crt.config_or_err()?;
match i18n_config.gettext {
Some(_) => {
gettext_impl::run(crt)?;
}
None => {}
}
Ok(())
}
#[cfg(feature = "localize")]
pub fn localizer() -> Box<dyn Localizer<'static>> {
Box::from(DefaultLocalizer::new(&LANGUAGE_LOADER, &TRANSLATIONS))
}