Documentation
¶
Overview ¶
Package i18n reads lich's translation catalogs: locales/<tag>/<namespace>.json, one tree per namespace, looked up by a dotted key ("settings.title"). A message holds {name} placeholders or is an object of CLDR plural forms picked by an int "count". lich's window reads its own catalogs with this package, and an extension reads its own with Bundle.
Index ¶
- Constants
- Variables
- func Fill(text string, args Args) (string, error)
- func Match(tag string, among []string) string
- func PluralForm(tag string, n int) string
- func SurfaceTitleKey(id string) string
- func TagFromEnv(getenv func(string) string) string
- type Args
- type Bundle
- type Catalog
- type Language
- type Message
Constants ¶
const LocalesDir = "locales"
LocalesDir is the folder of an extension's catalogs, beside its manifest.
const (
ManifestNameKey = "extension.manifest.name"
)
The keys lich reads an extension's manifest strings from, in the namespace "extension" (locales/<tag>/extension.json). A key a catalog lacks reads the manifest's own text.
const Source = "en"
Source is the language catalogs are written in first, and the one a message missing from a translation falls back to.
Variables ¶
var ErrNoCount = errors.New("is a plural and needs an int count")
ErrNoCount is a plural asked for without an int count.
var Placeholder = regexp.MustCompile(`\{(\w+)\}`)
Placeholder matches a {name} in a message.
Functions ¶
func Fill ¶
Fill puts args' values in text's placeholders. A placeholder without a value is left as it is and named in the error.
func Match ¶
Match is the tag of among that tag reads: an exact match, ignoring case, then a language match (any Portuguese reads pt-BR), then "".
func PluralForm ¶
PluralForm is the CLDR plural category of an integer count in the language tag, any case. Only the forms lich's catalogs use are told apart: Spanish's "many" (1000000 and up) has no message of its own and reads "other" either way, and a language lich has no rule for reads "other" always.
func SurfaceTitleKey ¶
SurfaceTitleKey is the key of surface id's title.
func TagFromEnv ¶
TagFromEnv is the POSIX locale the environment names, in the order glibc reads it for messages (LC_ALL, LC_MESSAGES, LANG), as a BCP 47 tag: pt_BR.UTF-8@euro reads pt-BR. C and POSIX name no language.
Types ¶
type Args ¶
Args are a message's placeholder values by name; "count" picks a plural's form and must be an int.
type Bundle ¶
type Bundle struct {
// contains filtered or unexported fields
}
Bundle is every catalog an extension ships, by tag as its folder names it.
func Open ¶
Open reads locales/<tag>/<namespace>.json under fsys. A missing locales folder is an empty bundle, which answers every key with itself.
func OpenDir ¶
OpenDir is Open on the folder dir, an extension's own: the folder its executable runs in.
func (*Bundle) In ¶
In is the message under key in the language tag, its placeholders filled from args: English when the tag's catalog lacks it, and the key itself when no catalog has it. A plural without an int count reads its "other" form, and a placeholder without a value stays as written.
type Language ¶
type Language struct {
// contains filtered or unexported fields
}
Language is the tag lich shows its interface in, as an extension learns it: the environment at start, then the language field of every surface.opened and every language message, which the extension passes to Set. It is safe to use from any goroutine.
func FromEnv ¶
func FromEnv() *Language
FromEnv starts from the variable lich starts an extension with, English when it is unset.