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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
use *;
/// Interpolates `{name}`-style placeholders in `template` from the
/// supplied `vars` map.
///
/// Walks the template once and replaces every `{key}` segment whose
/// key is present in `vars`. Placeholders whose key is missing are
/// left as the literal `{key}` token — matching the i18next
/// default behaviour. No escaping is performed: callers that need
/// it must escape themselves.
///
/// Returns the interpolated `String`. Empty / no-placeholder
/// templates round-trip unchanged.
///
/// # Arguments
///
/// - `&str` - The template containing `{key}` placeholders.
/// - `&HashMap<&'static str, &'static str>` - The variable map. A
/// static-borrowed key list is enough because the typical
/// consumer (`I18n::t_with`) builds the map inline.
///
/// # Returns
///
/// - `String` - The interpolated string.
pub
/// Obtains the i18n handle registered against the current hook context slot.
///
/// Behaves like `HookContext::use_hook`: the same `I18n` is returned
/// on every render at the same hook index, preserving the locale,
/// fallback locale, and message table across renders.
///
/// The initial `locale` defaults to `"en"`; pass `init_locale` to
/// change it on the first render. Call [`I18n::add_messages`] to
/// register translations under each locale tag.
///
/// # Arguments
///
/// - `&str` - The initial locale tag. Defaults to `"en"` if the
/// empty string is supplied (so a wrapper can pass `""` to adopt
/// the default).
///
/// # Returns
///
/// - `I18n` - The i18n handle.
/// Returns the factory result directly when no hook context is
/// active (e.g. when called outside a render cycle).
/// Registers a translation `key -> message` under `locale` on the
/// supplied i18n handle.
///
/// Pair with [`use_i18n`]: the typical pattern is to call this in
/// an `App::use_cleanup`-style mount phase so the same translations
/// stay registered across renders.
///
/// The `&'static` lifetime bound matches the internal
/// `MessageEntry` type alias (`(&'static str, &'static str)`);
/// in practice the call site passes an array literal that the
/// compiler naturally satisfies from string-literal promotion.
///
/// # Arguments
///
/// - `I18n` - The i18n handle obtained from `use_i18n()`.
/// - `&str` - The locale tag (e.g. `"en"`, `"zh-CN"`).
/// - `&[(&'static str, &'static str)]` - The `(key, message)` pairs.
/// Internally forwarded as `&[MessageEntry]`.
///
/// # Panics
///
/// This function does not panic.
/// Clears every registered translation from the process-wide
/// [`I18N_MESSAGES`] storage.
///
/// Intended for integration tests in `ui/tests/i18n/` that
/// rely on a clean table at the start of each case. Production
/// callers must never use this — translation tables are
/// expected to live for the lifetime of the app.