Documentation
¶
Index ¶
- Variables
- func RegisterTemplateHelpers() error
- type Config
- func (c Config) Fallbacks(locale string) []string
- func (c Config) HelperConfig() interfaces.HelperConfig
- func (c Config) LocaleCodes() []string
- func (c Config) MarshalJSON() ([]byte, error)
- func (c *Config) UnmarshalJSON(data []byte) error
- func (c *Config) WithFallbacks(locale string, fallbacks ...string)
- type Fixture
- type Loader
- type LocaleConfig
- type MissingTranslationStrategy
- type NoOpService
- type Service
- type ServiceOptions
- type TemplateHelpersFunc
- type TemplateHelpersProvider
Constants ¶
This section is empty.
Variables ¶
var ErrMissingTranslation = errors.New("i18n: missing translation")
ErrMissingTranslation is returned when no translation can be resolved.
Functions ¶
func RegisterTemplateHelpers ¶
func RegisterTemplateHelpers() error
Types ¶
type Config ¶
type Config struct {
DefaultLocale string `json:"default_locale"`
Locales []LocaleConfig `json:"locales"`
TemplateHelperKey string `json:"template_helper_key"`
LocaleContextKey string `json:"locale_context_key"`
}
Config bridges CMS locale configuration to the i18n service.
func FromModuleConfig ¶
FromModuleConfig produces the i18n config given CMS configuration values.
func (Config) HelperConfig ¶
func (c Config) HelperConfig() interfaces.HelperConfig
HelperConfig converts the module config into an interfaces.HelperConfig.
func (Config) LocaleCodes ¶
LocaleCodes returns the set of configured locale codes.
func (Config) MarshalJSON ¶
MarshalJSON implements json.Marshaler ensuring we serialise unique locales.
func (*Config) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler for Config.
func (*Config) WithFallbacks ¶
WithFallbacks registers fallbacks for the provided locale code.
type Fixture ¶
type Fixture struct {
Config Config `json:"config"`
Translations map[string]map[string]string `json:"translations"`
}
Fixture represents a serialised bundle of configuration + translations.
func DefaultFixture ¶
DefaultFixture loads the built-in translation fixture.
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader reads translation fixtures from disk.
type LocaleConfig ¶
type LocaleConfig struct {
Code string `json:"code"`
Fallbacks []string `json:"fallbacks,omitempty"`
}
LocaleConfig describes a locale definition and its fallback behaviour.
type MissingTranslationStrategy ¶
MissingTranslationStrategy defines how helpers handle missing translations.
type NoOpService ¶
type NoOpService struct{}
NoOpService is a placeholder that satisfies the contract without performing translations.
func (NoOpService) Culture ¶
func (NoOpService) Culture() interfaces.CultureService
func (NoOpService) DefaultLocale ¶
func (NoOpService) DefaultLocale() string
func (NoOpService) TemplateHelpers ¶
func (NoOpService) TemplateHelpers(cfg interfaces.HelperConfig) map[string]any
func (NoOpService) Translator ¶
func (NoOpService) Translator() interfaces.Translator
type Service ¶
type Service interface {
interfaces.Service
}
Service aggregates translator + helper wiring.
func NewInMemoryService ¶
NewInMemoryService creates a service backed by the provided translations.
func NewService ¶
func NewService(opts ServiceOptions) Service
NewService constructs a concrete Service from the provided options.
type ServiceOptions ¶
type ServiceOptions struct {
Translator interfaces.Translator
Culture interfaces.CultureService
Helpers TemplateHelpersProvider
DefaultLocale string
FallbackOnError MissingTranslationStrategy
}
ServiceOptions configures the concrete i18n service.
type TemplateHelpersFunc ¶
type TemplateHelpersFunc func(interfaces.Translator, interfaces.HelperConfig, MissingTranslationStrategy) map[string]any
TemplateHelpersFunc adapts a function into a TemplateHelpersProvider.
func (TemplateHelpersFunc) TemplateHelpers ¶
func (fn TemplateHelpersFunc) TemplateHelpers(tr interfaces.Translator, cfg interfaces.HelperConfig, fallback MissingTranslationStrategy) map[string]any
TemplateHelpers satisfies TemplateHelpersProvider.
type TemplateHelpersProvider ¶
type TemplateHelpersProvider interface {
TemplateHelpers(translator interfaces.Translator, cfg interfaces.HelperConfig, fallback MissingTranslationStrategy) map[string]any
}
TemplateHelpersProvider builds helper maps for template renderers.