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 ¶
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 ¶
BlogPostSlugs returns all blog post slugs in the given directory.
func BlogTranslationLangs ¶
BlogTranslationLangs returns the list of languages for which a translation exists.
func BlogTranslationPath ¶
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 ¶
ParseBlogPost reads a Markdown file with YAML frontmatter.
func ParseBlogPostData ¶
ParseBlogPostData parses blog post data from bytes.
func (*BlogPost) IsTranslatedBlog ¶
IsTranslatedBlog returns true if the blog post has translated title and content.
func (*BlogPost) WriteBlogPost ¶
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 (*File) Marshal ¶
Marshal produces the JSON output matching the original i18next format with 4-space indentation and sorted keys.
func (*File) UntranslatedKeys ¶
UntranslatedKeys returns keys that have empty translations.
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.