Documentation
¶
Overview ¶
Package i18next implements reading and writing of i18next JSON translation files.
The expected file format is:
{
"_meta": { "name": "Русский", "flag": "🇷🇺" },
"translations": {
"English key text": "Translated value",
"Another key": ""
}
}
Keys are natural English text. Empty string values mean untranslated (i18next falls back to the key itself as the English text).
Index ¶
- Variables
- type File
- func (f *File) Keys() []string
- func (f *File) Marshal() ([]byte, error)
- func (f *File) Set(key, value string) bool
- func (f *File) SourceValues() map[string]string
- func (f *File) Stats() (total, translated int, pct float64)
- func (f *File) UntranslatedKeys() []string
- func (f *File) WriteFile(path string) error
- type Meta
Constants ¶
This section is empty.
Variables ¶
var LangMeta = func() map[string]Meta { out := make(map[string]Meta, len(langmeta.Registry)) for k, v := range langmeta.Registry { out[k] = Meta{Name: v.Name, Flag: v.Flag} } return out }()
LangMeta contains known language metadata for auto-fill.
Functions ¶
This section is empty.
Types ¶
type File ¶
type File struct {
Meta Meta
Translations map[string]string // key (English) -> value (translated)
// contains filtered or unexported fields
}
File represents a parsed i18next translation file.
func (*File) Marshal ¶
Marshal produces the JSON output matching the original i18next format with 4-space indentation and sorted keys.
func (*File) SourceValues ¶ added in v0.9.2
SourceValues returns key -> source string mapping. In i18next files keys are natural English source strings.
func (*File) UntranslatedKeys ¶
UntranslatedKeys returns keys that have empty translations.
type Meta ¶
Meta holds the language metadata from the _meta field.
func ResolveMeta ¶
ResolveMeta returns best-effort language metadata for language codes, supporting variants like pt_BR, pt-BR, and region fallbacks.