Documentation
¶
Overview ¶
Package i18n is gettext in pure Go: GNU .mo and .po catalogs with plural forms and message contexts, locale resolution from the environment, and catalog lookup in a file system. A Catalog plugs into lys-ui's widget.SetMessageCatalog, so a toolkit's built-in strings and an app's own translate through one table.
cat, err := i18n.LoadSystem("myapp", i18n.Locales())
label := cat.Get("Open")
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Catalog ¶
type Catalog struct {
// contains filtered or unexported fields
}
Catalog is one language's translations. The zero value translates nothing: every lookup returns its English input.
func FromMap ¶
FromMap is a catalog from a plain English-to-translation map, for apps that keep a handful of strings in code. It has no plural forms or contexts.
func Load ¶
Load finds domain's catalog in fsys for the first locale that has one, as <locale>/LC_MESSAGES/<domain>.mo or .po. An empty catalog (the identity) and no error mean no locale has one; a catalog that exists but does not parse is an error.
func LoadSystem ¶
LoadSystem is Load over the system's locale directories: each directory of xdg.Env.DataSearchPath's locale directory, first match wins.
func ParsePO ¶
ParsePO parses a .po catalog. Fuzzy entries are skipped, as msgfmt skips them; the header is kept for its Plural-Forms.