i18n: extract include_i18n macro use into method for consistent compilation order
This commit is contained in:
parent
e4718d7598
commit
a9c4786d14
|
@ -292,8 +292,9 @@ pub fn pop_mail(dir: &Path) -> Result<Option<String>> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::web::get_i18n;
|
||||
|
||||
use super::*;
|
||||
use gettext_macros::include_i18n;
|
||||
use std::str::FromStr;
|
||||
use tempfile::{tempdir, TempDir};
|
||||
|
||||
|
@ -302,7 +303,7 @@ mod test {
|
|||
const TO: &str = "recipient@example.org";
|
||||
|
||||
fn configure_i18n(lang: &'static str) -> I18n {
|
||||
let langs = include_i18n!();
|
||||
let langs = get_i18n();
|
||||
let catalog = langs
|
||||
.clone()
|
||||
.into_iter()
|
||||
|
|
|
@ -3,9 +3,8 @@ use std::path::{Path, PathBuf};
|
|||
|
||||
use handlebars::Handlebars;
|
||||
|
||||
use gettext_macros::include_i18n;
|
||||
|
||||
use crate::i18n::I18NHelper;
|
||||
use crate::web::get_i18n;
|
||||
use crate::Result;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -55,7 +54,7 @@ fn load_localized_template_names(
|
|||
pub fn load_handlebars(template_dir: &Path) -> Result<Handlebars<'static>> {
|
||||
let mut handlebars = Handlebars::new();
|
||||
|
||||
let i18ns = include_i18n!();
|
||||
let i18ns = get_i18n();
|
||||
let i18n_helper = I18NHelper::new(i18ns);
|
||||
handlebars.register_helper("text", Box::new(i18n_helper));
|
||||
|
||||
|
|
|
@ -396,6 +396,12 @@ pub fn serve() -> Result<rocket::Rocket<rocket::Build>> {
|
|||
|
||||
compile_i18n!();
|
||||
|
||||
// The include_i18n macro must be called after compile_i18n, which must be called after i18n macros
|
||||
// *in compilation order*. We use a helper function here to make this order consistent.
|
||||
pub fn get_i18n() -> Vec<(&'static str, gettext::Catalog)> {
|
||||
include_i18n!()
|
||||
}
|
||||
|
||||
fn rocket_factory(
|
||||
mut rocket: rocket::Rocket<rocket::Build>,
|
||||
) -> Result<rocket::Rocket<rocket::Build>> {
|
||||
|
@ -467,14 +473,14 @@ fn rocket_factory(
|
|||
|
||||
rocket = rocket
|
||||
.attach(Template::custom(|engines: &mut Engines| {
|
||||
let i18ns = include_i18n!();
|
||||
let i18ns = get_i18n();
|
||||
let i18n_helper = I18NHelper::new(i18ns);
|
||||
engines
|
||||
.handlebars
|
||||
.register_helper("text", Box::new(i18n_helper));
|
||||
}))
|
||||
.attach(maintenance_mode)
|
||||
.manage(include_i18n!())
|
||||
.manage(get_i18n())
|
||||
.manage(hagrid_state)
|
||||
.manage(stateless_token_service)
|
||||
.manage(stateful_token_service)
|
||||
|
@ -594,7 +600,6 @@ pub mod tests {
|
|||
use mail::pop_mail;
|
||||
|
||||
use super::*;
|
||||
use crate::database::*;
|
||||
|
||||
/// Fake base URI to use in tests.
|
||||
const BASE_URI: &str = "http://local.connection";
|
||||
|
|
Loading…
Reference in New Issue