Documentation
¶
Overview ¶
SPDX-License-Identifier: MPL-2.0 Package localize loads immutable, data-only message catalogs. Products own source selection, preference persistence and explicit replacement on reload. It imports neither the Admin shell nor Core and performs no lookup-time I/O.
SPDX-License-Identifier: MPL-2.0
Index ¶
Constants ¶
const ( MaxSources = 32 MaxFiles = 128 MaxEntries = 4096 MaxFileBytes = 256 << 10 MaxTotalBytes = 4 << 20 MaxMessages = 8192 MaxLocales = 32 MaxDomains = 64 MaxMessageBytes = 8 << 10 MaxOutputBytes = 32 << 10 MaxParameters = 32 MaxParameterBytes = 8 << 10 )
Fixed limits bound startup work, retained catalogs and formatted output.
Variables ¶
var ( ErrCatalog = errors.New("invalid localization catalog") ErrLocale = errors.New("unsupported localization locale") ErrMessage = errors.New("unknown localization message") ErrParameters = errors.New("invalid localization parameters") ErrLimit = errors.New("localization limit exceeded") )
Functions ¶
This section is empty.
Types ¶
type Catalog ¶
type Catalog struct {
// contains filtered or unexported fields
}
Catalog is immutable after Load and safe for concurrent readers. There is no process-global locale and no automatic file watcher. Load a replacement before publishing it through the product's own instance/reload lifecycle.
func Load ¶
Load reads all .json files below each source root once. Use fs.Sub for embedded Module roots and a product-selected fs.FS for installed language packs. Sources add domains/messages, not ordered overrides: duplicate identities are errors. Symlinks, nonregular JSON files, excessive depth and unsupported directory readers are rejected. The owner must also trust the supplied FS root itself.
type Forms ¶
type Forms struct {
Zero string `json:"zero,omitempty"`
One string `json:"one,omitempty"`
Two string `json:"two,omitempty"`
Few string `json:"few,omitempty"`
Many string `json:"many,omitempty"`
Other string `json:"other"`
}
Forms contains complete messages, not HTML or executable templates. Other is required; absent categories use Other. Parameters use {Name}; {{ and }} escape literal braces. Plural uses CLDR cardinal categories for integral quantities.
type Locale ¶
type Locale struct {
Tag string `json:"tag"`
Name string `json:"name"`
Direction string `json:"direction"`
}
Locale is presentation metadata, not a content, calendar or permission policy.
type Localizer ¶
type Localizer struct {
// contains filtered or unexported fields
}
Localizer is an immutable per-selection view. It does not store preferences or alter the original content. Returned text remains untrusted display data and must use the output context's normal escaping, including html/template or DOM textContent. Never cast it to trusted HTML or execute it as a template/script.
func (*Localizer) Messages ¶
Messages returns a defensive, English-fallback-completed browser message table for one domain. It contains data-only patterns and the source locale of each complete message. Client plural selection must use Message.Locale, not necessarily the document locale; absent categories use Forms.Other. Serialize with normal encoding/json escaping and consume values through safe DOM text.
func (*Localizer) Plural ¶
func (l *Localizer) Plural(domain, key string, count int64, params map[string]string) (string, error)
Plural selects a cardinal form for an integral count using maintained CLDR rules. It injects the decimal Count parameter without changing calendar, number/currency formatting or stored values. Params must not supply Count.
func (*Localizer) Text ¶
Text formats the complete Other message. Missing translations fall back as a whole message to English; unknown keys or missing parameters return errors. Valid extra parameters are accepted to allow a shared caller-owned parameter set. Values are strings, not executable templates or locale-formatting policy.