Documentation
¶
Overview ¶
Package i18n is a platform module: translations of API responses and error messages, ported from taply. Requires postgres and api.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Configure ¶ added in v0.11.0
Configure applies options to the i18n module among the modules, for a project whose wiring is generated: call it in main, between platformModules and platform.Run.
func SkipTranslation ¶
SkipTranslation turns response substitution off for the calls fn picks — taply does it for tablets of a restaurant with translations disabled. fn runs after the project's authentication, so it sees the caller the authentication put into the context. Error messages are still translated.
Types ¶
type Config ¶
type Config struct {
DefaultLocale i18nx.Locale // language of the base columns and the fallback
Locales []i18nx.Locale // languages the API answers in
}
Config holds module settings. Load fills it from the environment; the platform generator writes the Load call into the project's config.gen.go.
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module implements platform.Module.
type Option ¶
type Option func(*Module)
Option configures the module.
func WithErrorPhase ¶ added in v0.11.0
WithErrorPhase moves the translation of error messages to another phase of the API chain. By default it is api.PhaseErrorsI18n, outside authentication, so the refusals of authentication, guards and validation are translated too. api.PhaseAfterValidate translates only what the handler and the phases after validation return, as taply did: a 400, 401 or 403 of the chain keeps its text whatever Accept-Language says.
func WithExternalErrors ¶ added in v0.11.1
func WithExternalErrors() Option
WithExternalErrors translates the failures of external providers too, as taply does: api.ExternalTimeout("zebra", "external service timeout") gets the translation of the key "error.msg.zebra: external service timeout" of i18n/messages.yaml in the language of the request; without an entry the message keeps its text, and the ErrorInfo stays. Off by default, the text names the provider and is left alone. An Unavailable, as api.ExternalUnavailable builds it, is never translated, like any Unavailable.
func WithMessages ¶
WithMessages gives the module the static translations of the project. The generated wiring passes the embedded i18n/messages.yaml.