Internationalization
The component library ships built-in text packs for 10 languages and lets hosts register custom languages. The mechanism mirrors the web bloodline's @lh-ui/share LhLocale semantics and is structurally identical to the iOS LhColors theming layer.
Language coverage
| Code | Language | Notes |
|---|---|---|
zh-CN | 简体中文 | Default language |
zh-TW | 繁體中文 | |
en-US | English | |
ja-JP | 日本語 | |
ko-KR | 한국어 | |
de-DE | Deutsch | Runtime only (the 9 doc-site languages exclude German) |
fr-FR | Français | |
es | Español | |
ar | العربية | RTL; layout flips automatically via the \.locale injected by LhTheme |
ru | Русский |
The codes match the web bloodline
lh-ui-shareLH_LANGUAGE_CONSTverbatim; the zh-CN confirm/cancel values come fromspecs/*.json("确认"/"取消", R-n5).
Scope (important)
LhTexts only carries the component library's own built-in strings:
- Dialog / Picker default confirm/cancel button text (when
confirmText/cancelTextisnil) - Loading / Switch accessibility labels, and the Input / Textarea accessibility fallback when no placeholder is set
Localization of caller-supplied text (title / content / label / options …) is the host app's responsibility — those strings come from business code and the library does not manage them.
Switching languages
// Global switch: LhTheme holds the singleton via @ObservedObject,
// so switching re-renders the whole tree
LhLocale.shared.setLocale("en-US")
// Current language code
LhLocale.shared.current // "en-US"LhTheme automatically injects the current pack into Environment(\.lhTexts) and drives \.locale (ar is RTL automatically). Unregistered languages fall back to the Simplified Chinese pack content (same as the web bloodline).
Custom languages
let vietnamese = LhTexts(
dialogConfirm: "Xác nhận", dialogCancel: "Hủy",
pickerConfirm: "Xác nhận", pickerCancel: "Hủy",
loadingLabel: "Đang tải", switchLabel: "Công tắc",
inputLabelFallback: "Trường văn bản",
textareaLabelFallback: "Trường văn bản nhiều dòng"
)
LhLocale.shared.register("vi", pack: vietnamese)
LhLocale.shared.setLocale("vi")register packs shadow the built-in registry (built-in packs are never overwritten); if the registered language is the current one, it applies immediately.
LhTexts
public struct LhTexts: Equatable, Sendable {
public let dialogConfirm: String // "确认" / "OK" / "確定" …
public let dialogCancel: String
public let pickerConfirm: String
public let pickerCancel: String
public let loadingLabel: String // accessibility label
public let switchLabel: String
public let inputLabelFallback: String
public let textareaLabelFallback: String
}
public let ZhCnLhTexts = LhTexts(dialogConfirm: "确认", /* … */)
public let EnUsLhTexts = LhTexts(dialogConfirm: "Confirm", /* … */)
// … ZhTw / JaJp / KoKr / DeDe / FrFr / Es / Ar / RuThe initializer is public so unit tests can construct packs directly. Without a LhTheme wrapper the environment key's defaultValue falls back to ZhCnLhTexts (defaults to Chinese, mirroring the theme layer's "defaults to light").
Relation to the theming layer
| Colors | Texts | |
|---|---|---|
| Value type | LhColors | LhTexts |
| Presets | LightLhColors / DarkLhColors | ZhCnLhTexts / EnUsLhTexts … |
| Injection | Environment(\.lhColors) | Environment(\.lhTexts) |
| Container | LhTheme(isDark:) | LhTheme internally (LhLocale.shared) |
| Scoped override | .lhColors(_) | .lhTexts(_) |
The texts parameter of LhTheme(isDark:colors:texts:) provides an explicit override entry point (preset text packs, reserved extension).
Docs app demo
The native docs host (LhDocsView) provides theme (system / light / dark) and language (10 built-ins plus a vi custom-pack demo) switching in the sidebar "设置" section for verifying multilingual behavior directly.

