catalog

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package catalog reads gotext message catalogs: one directory per locale under a locales directory, each holding messages.gotext.json and out.gotext.json.

Index

Constants

View Source
const (
	// BaseLocale is the source locale every other locale translates from.
	BaseLocale = "en-US"
	// MessagesFile is a locale's curated catalog, where translators write translations.
	MessagesFile = "messages.gotext.json"
	// OutFile is the catalog gotext extracts from source on each run.
	OutFile = "out.gotext.json"
)

Variables

This section is empty.

Functions

func LocaleDirs

func LocaleDirs(localesDir string) ([]string, error)

LocaleDirs returns the sorted locale directories under localesDir, following symlinks. It skips files, such as a stray .DS_Store, and hidden directories.

func Placeholders

func Placeholders(text string) []string

Placeholders returns the placeholders in text, such as {Name}, in order of appearance.

Types

type Catalog

type Catalog struct {
	Language string    `json:"language"`
	Messages []Message `json:"messages"`
}

Catalog is one locale's gotext catalog.

func Load

func Load(path string) (*Catalog, error)

Load reads the catalog at path.

type Document

type Document struct {
	// contains filtered or unexported fields
}

Document edits a catalog file without disturbing what it doesn't change: every entry keeps its fields, field order, and id form, and unknown fields survive. Save reindents the file with the indent it was read with.

func LoadDocument

func LoadDocument(path string) (*Document, error)

LoadDocument reads the catalog at path for editing.

func (*Document) AppendFrom

func (d *Document) AppendFrom(source *Document, id ID, text string) error

AppendFrom adds a copy of source's entry for id, translated as text. source is usually the base locale, so the new entry carries its message, placeholders, and comments.

func (*Document) Save

func (d *Document) Save(path string) error

Save writes the document to path atomically, keeping the file's permissions.

func (*Document) SetTranslation

func (d *Document) SetTranslation(id ID, text string) (bool, error)

SetTranslation sets the translation of the entry with id and reports whether one exists.

type ID

type ID string

ID is a message id. gotext writes it as a string or as a [key, fallback] array; ID keeps the first element.

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts both id forms.

type Message

type Message struct {
	ID          ID     `json:"id"`
	Message     string `json:"message"`
	Translation any    `json:"translation"`
}

Message is one catalog entry. Translation is a string, or an object for plural and select messages.

func (Message) Text

func (m Message) Text() (string, bool)

Text returns the translation when it is a string.

func (Message) Untranslated

func (m Message) Untranslated() bool

Untranslated reports whether the message has no translation, or an empty one.

Jump to

Keyboard shortcuts

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