i18next

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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 Parse

func Parse(data []byte) (*File, error)

Parse parses i18next JSON data.

func ParseFile

func ParseFile(path string) (*File, error)

ParseFile reads and parses an i18next JSON translation file.

func (*File) Keys

func (f *File) Keys() []string

Keys returns the translation keys in their original order.

func (*File) Marshal

func (f *File) Marshal() ([]byte, error)

Marshal produces the JSON output matching the original i18next format with 4-space indentation and sorted keys.

func (*File) Stats

func (f *File) Stats() (total, translated, untranslated int)

Stats returns (total, translated, untranslated) counts.

func (*File) UntranslatedKeys

func (f *File) UntranslatedKeys() []string

UntranslatedKeys returns keys that have empty translations.

func (*File) WriteFile

func (f *File) WriteFile(path string) error

WriteFile writes the translation file back to disk in the original format, preserving key order and using 4-space indentation.

type Meta

type Meta struct {
	Name string `json:"name"`
	Flag string `json:"flag"`
}

Meta holds the language metadata from the _meta field.

func ResolveMeta

func ResolveMeta(lang string) Meta

ResolveMeta returns best-effort language metadata for language codes, supporting variants like pt_BR, pt-BR, and region fallbacks.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL