Documentation
¶
Overview ¶
i18n is a simple package that translates strings using a language map. It mimics some functionality of the vue-i18n library so that the same JSON language map may be used in the JS frontend and the Go backend.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type I18n ¶
type I18n struct {
// contains filtered or unexported fields
}
I18n offers translation functions over a language map.
func (*I18n) Load ¶
Load loads a JSON language map into the instance overwriting existing keys that conflict.
func (*I18n) Tc ¶
Tc returns the translation for the given key similar to vue i18n's tc(). It expects the language string in the map to be of the form `Singular | Plural` and returns `Plural` if n > 1, or `Singular` otherwise.
func (*I18n) Ts ¶
Ts returns the translation for the given key similar to vue i18n's t() and substitutes the params in the given map in the translated value. In the language values, the substitutions are represented as: {key} The params and values are received as a pairs of succeeding strings. That is, the number of these arguments should be an even number. eg: Ts("globals.message.notFound",
"name", "campaigns", "error", err)