mod bundle;
mod catalog;
mod locale;
#[cfg(any(feature = "platform", feature = "web-axum"))]
mod middleware;
mod translate;
use std::sync::{Arc, OnceLock};
use crate::config::settings::I18nSettings;
pub use bundle::{I18nBundle, Locale};
pub use locale::{
detect_locale_from, detect_system_locale, negotiate_locale, parse_accept_language,
resolve_startup_default_locale, BUILTIN_DEFAULT_LOCALE,
};
#[cfg(any(feature = "platform", feature = "web-axum"))]
pub use middleware::i18n_middleware;
pub use translate::{t, t_with_args, tr_log, tr_log_args};
static STARTUP_BUNDLE: OnceLock<Arc<I18nBundle>> = OnceLock::new();
static STARTUP_LOCALE: OnceLock<Locale> = OnceLock::new();
pub fn build_startup_bundle(cfg: &I18nSettings) -> Option<Arc<I18nBundle>> {
let supported: Vec<&str> = cfg.supported_locales.iter().map(|s| s.as_str()).collect();
let default_locale = resolve_startup_default_locale(&cfg.default_locale, &supported);
I18nBundle::load(&default_locale.to_string(), &supported)
.map(Arc::new)
.ok()
}
pub fn init_startup_i18n(bundle: Arc<I18nBundle>) {
let _ = STARTUP_LOCALE.set(bundle.default_locale().clone());
let _ = STARTUP_BUNDLE.set(bundle);
}
pub fn startup_i18n() -> Option<(&'static Locale, &'static Arc<I18nBundle>)> {
let locale = STARTUP_LOCALE.get()?;
let bundle = STARTUP_BUNDLE.get()?;
Some((locale, bundle))
}