i18next

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 6 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).

Recipe translation files use a simpler format:

{
    "name": "Translated name",
    "description": "Translated description",
    "longDescription": "Translated long description"
}

Index

Constants

This section is empty.

Variables

View Source
var LangMeta = map[string]Meta{
	"en":    {Name: "English", Flag: "🇺🇸"},
	"ru":    {Name: "Русский", Flag: "🇷🇺"},
	"de":    {Name: "Deutsch", Flag: "🇩🇪"},
	"es":    {Name: "Español", Flag: "🇪🇸"},
	"fr":    {Name: "Français", Flag: "🇫🇷"},
	"it":    {Name: "Italiano", Flag: "🇮🇹"},
	"pt-BR": {Name: "Português (Brasil)", Flag: "🇧🇷"},
	"id":    {Name: "Bahasa Indonesia", Flag: "🇮🇩"},
	"ja":    {Name: "日本語", Flag: "🇯🇵"},
	"ko":    {Name: "한국어", Flag: "🇰🇷"},
	"zh-CN": {Name: "简体中文", Flag: "🇨🇳"},
	"zh-TW": {Name: "繁體中文", Flag: "🇹🇼"},
	"ar":    {Name: "العربية", Flag: "🇸🇦"},
	"tr":    {Name: "Türkçe", Flag: "🇹🇷"},
	"pl":    {Name: "Polski", Flag: "🇵🇱"},
	"uk":    {Name: "Українська", Flag: "🇺🇦"},
	"nl":    {Name: "Nederlands", Flag: "🇳🇱"},
	"sv":    {Name: "Svenska", Flag: "🇸🇪"},
	"cs":    {Name: "Čeština", Flag: "🇨🇿"},
	"ro":    {Name: "Română", Flag: "🇷🇴"},
	"hu":    {Name: "Magyar", Flag: "🇭🇺"},
	"el":    {Name: "Ελληνικά", Flag: "🇬🇷"},
	"da":    {Name: "Dansk", Flag: "🇩🇰"},
	"fi":    {Name: "Suomi", Flag: "🇫🇮"},
	"no":    {Name: "Norsk", Flag: "🇳🇴"},
	"th":    {Name: "ไทย", Flag: "🇹🇭"},
	"vi":    {Name: "Tiếng Việt", Flag: "🇻🇳"},
	"hi":    {Name: "हिन्दी", Flag: "🇮🇳"},
}

LangMeta contains known language metadata for auto-fill.

Functions

func BlogPostSlugs

func BlogPostSlugs(postsDir string) ([]string, error)

BlogPostSlugs returns all blog post slugs in the given directory.

func BlogTranslationLangs

func BlogTranslationLangs(postsDir, slug string) []string

BlogTranslationLangs returns the list of languages for which a translation exists.

func BlogTranslationPath

func BlogTranslationPath(postsDir, slug, lang string) string

BlogTranslationPath returns the path to a blog post translation file.

Types

type BlogPost

type BlogPost struct {
	// Translatable fields
	Title   string
	Excerpt string
	Content string // Markdown body after frontmatter

	// Inherited fields (kept as-is from the source post)
	Author             string
	PublishedAt        string
	UpdatedAt          string
	Tags               []string
	FeaturedImage      string
	Published          bool
	Order              int
	TelegramDiscussion string
	TelegramPostId     int
}

BlogPost represents a parsed blog post with YAML frontmatter and Markdown body. Only translatable fields are exposed; inherited fields are preserved as raw YAML.

func ParseBlogPost

func ParseBlogPost(path string) (*BlogPost, error)

ParseBlogPost reads a Markdown file with YAML frontmatter.

func ParseBlogPostData

func ParseBlogPostData(data []byte) (*BlogPost, error)

ParseBlogPostData parses blog post data from bytes.

func (*BlogPost) IsTranslatedBlog

func (bp *BlogPost) IsTranslatedBlog() bool

IsTranslatedBlog returns true if the blog post has translated title and content.

func (*BlogPost) WriteBlogPost

func (bp *BlogPost) WriteBlogPost(path string) error

WriteBlogPost writes a blog post to disk as Markdown with YAML frontmatter.

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.

type RecipeTranslation

type RecipeTranslation struct {
	Name            string `json:"name"`
	Description     string `json:"description"`
	LongDescription string `json:"longDescription"`
}

RecipeTranslation represents a per-recipe translation file.

func ParseRecipeFile

func ParseRecipeFile(path string) (*RecipeTranslation, error)

ParseRecipeFile reads a recipe translation JSON file.

func (*RecipeTranslation) IsFullyTranslated

func (rt *RecipeTranslation) IsFullyTranslated() bool

IsFullyTranslated returns true if all three fields are non-empty.

func (*RecipeTranslation) IsTranslated

func (rt *RecipeTranslation) IsTranslated() bool

IsTranslated returns true if at least name and description are non-empty.

func (*RecipeTranslation) WriteRecipeFile

func (rt *RecipeTranslation) WriteRecipeFile(path string) error

WriteRecipeFile writes a recipe translation JSON file.

Jump to

Keyboard shortcuts

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