Initial commit of Descrybe v2 without local scratch artifacts.
Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
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,
|
||||
}
|
||||
Reference in New Issue
Block a user