Documentation
¶
Overview ¶
Package i18n resolves user-facing message codes into localized text.
Services raise errors with a stable code rather than a sentence:
httpserver.ConflictError(err, messages.PhoneNumberInUse)
The HTTP error handler looks the code up in the catalog registered on the server and renders it in the locale the caller asked for, so the response carries both the code a client can branch on and text a person can read.
Index ¶
Constants ¶
const ( CodeBadRequest = "BAD_REQUEST" CodeValidation = "VALIDATION_ERROR" CodeForbidden = "FORBIDDEN" CodeNotFound = "NOT_FOUND" CodeConflict = "CONFLICT" CodeInternal = "INTERNAL_ERROR" )
Generic message codes, one per status a handler can return without naming a specific rule. They are the fallback the error handler reports when a message is literal prose rather than a catalog code, so every error carries a code a client can branch on even before a service is fully migrated.
Variables ¶
This section is empty.
Functions ¶
func CodeForStatus ¶
CodeForStatus is the generic code reported for an HTTP status.
Types ¶
type Catalog ¶
Catalog maps a message code to its text in each locale. A code missing an entry for the requested locale falls back to Default.
func BuiltinCatalog ¶
func BuiltinCatalog() Catalog
BuiltinCatalog returns text for the generic codes. Services merge their own domain catalog over it; a service that wants a plain localized "not found" can raise CodeNotFound directly instead of inventing a code.