Skip to main content

euv_ui/hook/i18n/
struct.rs

1use super::*;
2
3/// The aggregate i18n state.
4///
5/// Constructed once per app via `App::use_i18n()`, threaded
6/// through any code that needs to render translated text.
7/// Cheap to `Clone` (the internal signal is
8/// `Copy`-by-pointer).
9///
10/// # Storage
11///
12/// Messages are stored in a `Signal<HashMap<String,
13/// HashMap<String, String>>>` keyed by `locale → (key →
14/// message)`. The map is intentionally two-level: it
15/// matches how translation files are typically organized
16/// (`en.json` is one flat key/value map, `zh-CN.json` is
17/// another, etc.) and it lets `add_messages(locale,
18/// &[(k, v), ...])` build the inner map by direct
19/// insertion without the user having to allocate one
20/// `HashMap` per locale.
21#[derive(Clone, Data, New)]
22pub struct I18n {
23    /// The currently-active locale tag. Setting this
24    /// via `set_locale` triggers a reactive update that
25    /// re-evaluates any reactive `t(...)` read.
26    pub(crate) locale: Signal<String>,
27    /// The locale to fall back to when a key is missing
28    /// in the active locale. Defaults to `"en"`.
29    pub(crate) fallback_locale: Signal<String>,
30    /// The full translation table. The outer key is the
31    /// locale tag, the inner key is the message key, the
32    /// inner value is the (optionally placeholder-
33    /// containing) message.
34    pub(crate) messages: Signal<HashMap<String, HashMap<String, String>>>,
35}