Documentation
¶
Overview ¶
Package i18n holds the languages Exhale speaks and the translations of what chat and the service say (ADR 0023).
Texts are written in English where they are used; English is the key of every translation. A language is registered in languages.json (read by the web too) and translated in locales/<code>.json, a flat JSON object from the English text to its translation. An entry may be left empty (""): the text falls back to English. A text counted with a number may give one translation per plural category instead of a string, for example {"one": "…", "few": "…", "many": "…", "other": "…"}.
docs/guides/translating.md explains how to add a language.
Index ¶
- Constants
- func Catalog(lang string) map[string]Entry
- func HasPluralRule(lang string) bool
- func Match(codes ...string) string
- func Name(code string) string
- func Plural(lang string, n int, one, other string) string
- func PluralCategories(lang string) []string
- func PluralCategory(lang string, n int) string
- func Supported(code string) bool
- func Translate(lang, text string) string
- type Entry
- type Language
Constants ¶
const ( Zero = "zero" One = "one" Two = "two" Few = "few" Many = "many" Other = "other" )
Plural categories, named as CLDR names them.
const Source = "en"
Source is the language the texts are written in.
Variables ¶
This section is empty.
Functions ¶
func Catalog ¶
Catalog returns the translations of a language, keyed by the English text (nil for English). The map is shared: do not change it.
func HasPluralRule ¶
HasPluralRule reports whether the table above knows the language.
func Match ¶
Match returns the first registered language among codes such as "pt-BR" or "es" (what a browser or a chat platform reports), or English.
func Plural ¶
Plural picks the text for count n: the English one or other form, translated by the plural category of n in the language. When the other form has a translation per category, that wins.
func PluralCategories ¶
PluralCategories lists the categories a language uses, "other" last.
func PluralCategory ¶
PluralCategory returns the plural category of n in a language. A language without a rule counts like English.
Types ¶
type Entry ¶
Entry is the translation of one text: a string, or one string per plural category.
func (Entry) MarshalJSON ¶
MarshalJSON writes what UnmarshalJSON reads.
func (*Entry) UnmarshalJSON ¶
UnmarshalJSON reads a string or an object of plural forms.
type Language ¶
type Language struct {
// Code is the ISO 639-1 code: "es", "pt".
Code string `json:"code"`
// Name is the language's own name: "Español", "Português".
Name string `json:"name"`
// Complete languages must translate every text (a test fails
// otherwise); an incomplete one ships with English in the gaps.
Complete bool `json:"complete,omitempty"`
}
Language is a registered language.