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 widget.SetMessageCatalog, so lys-ui's built-in strings and an app's own translate through one table.
cat, err := i18n.LoadSystem("myapp", i18n.Locales())
widget.SetMessageCatalog(cat)
label := widget.Tr("Open")
count := fmt.Sprintf(widget.TrN("%d file", "%d files", n), n)
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 XDG data dir's locale directory (XDG_DATA_HOME, then XDG_DATA_DIRS, defaulting to /usr/local/share and /usr/share), 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.