use crate::app::config::Configuration;
use crate::i18n::I18NHelper;
use rocket::Build;
use rocket::Rocket;
use rocket::fairing::Fairing;
use rocket_dyn_templates::{Engines, Template};

pub fn init(_config: &Configuration) -> super::InfallibleResult<impl Fairing> {
    Ok(Some(Template::custom(|engines: &mut Engines| {
        let i18ns = crate::get_i18n();
        let i18n_helper = I18NHelper::new(i18ns);
        engines
            .handlebars
            .register_helper("text", Box::new(i18n_helper));
    })))
}

pub fn register(
    rocket: Rocket<Build>,
    _config: &Configuration,
    fairing: impl Fairing,
) -> Rocket<Build> {
    rocket.attach(fairing)
}
