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
//! i18n contract for gldf-rs.
//!
//! This module defines only the [`Translator`](crate::i18n::Translator) trait — the contract
//! that frontends (gldf-rs-wasm, gldf-rs-tui, gldf-rs-cli, gldf-rs-python)
//! implement to translate the `gldf.*` keys this crate emits. The
//! actual translation data lives in a separate crate
//! (`gldf-rs-i18n`) so this crate stays a pure logic/data crate and
//! doesn't ship JSON locale files.
//!
//! # Why a trait, not an embedded table
//!
//! Keeping data out of the library is deliberate:
//! - Headless callers (the CLI, Python bindings, tests) often don't
//! need translations; they shouldn't pay for the locale files.
//! - Frontends may already have their own translation backend (the
//! WASM viewer historically used `eulumdat-i18n`'s `extra` map for
//! shared keys).
//! - Translation files change shape over time; binding the library's
//! release cadence to a JSON schema would be friction.
//!
//! # i18n keys this library emits
//!
//! - `gldf.ral.<number>.name` — RAL Classic color name (213 entries,
//! one per [`crate::ral::RalEntry`]). Default fallbacks: German
//! (`name_de`) for `de*` locales, English (`name_en`) for everything
//! else.
//! - Future: validation messages, action error templates, reducer
//! diagnostics that surface to humans.
//!
//! # Default implementation
//!
//! [`NoOpTranslator`](crate::i18n::NoOpTranslator) returns `None` for every key. Useful in tests
//! and as a sentinel when the consumer hasn't wired translations.
//! Callers should treat `None` as "fall back to whatever string the
//! library provides alongside the key" (e.g. `RalEntry::fallback_name`).
/// Translate a key in a target language. Implementors return:
///
/// - `Some(text)` if a translation exists in the requested language
/// - `Some(text)` if only an English fallback is available (the
/// implementor decides — `None` is also acceptable in that case)
/// - `None` if neither the requested language nor any fallback is
/// registered for the key
///
/// `language_code` is a BCP-47 stem (`"de"`, `"en"`, `"fr"`, …). The
/// trait does not enforce a closed list; implementors map unknown
/// codes to English (or whatever default they prefer).
/// A no-op [`Translator`] that always returns `None`. Useful as a
/// default when the consumer hasn't installed a real translation
/// backend. The library treats `None` as "use the in-code fallback".
;