package i18n // Stable machine codes that must never be translated when used as the JSON // "error" / "code" field value. Clients branch on these exact strings. var stableCodes = map[string]struct{}{ "password_not_set": {}, "email_mismatch": {}, "maintenance": {}, "read_only": {}, "already_claimed": {}, "not_claimable": {}, "invalid_credentials": {}, "user_already_exists": {}, "password_too_short": {}, "register_fields_required": {}, } // IsStableCode reports whether msg is a machine-stable error token. func IsStableCode(msg string) bool { _, ok := stableCodes[msg] return ok } // T returns msg translated for locale. Missing entries fall back to English msg. // Stable machine codes are returned unchanged. func T(locale, msg string) string { if msg == "" || IsStableCode(msg) { return msg } lang := Normalize(locale) if lang == Default { return msg } if pack, ok := catalogs[lang]; ok { if translated, ok := pack[msg]; ok && translated != "" { return translated } } return msg } // catalogs maps locale → (English source message → translation). // English is the identity key; add entries here when introducing new public copy. var catalogs = map[string]map[string]string{ "es": esMessages, "fr": frMessages, "de": deMessages, "it": itMessages, "pt": ptMessages, "nl": nlMessages, "pl": plMessages, "ja": jaMessages, }