i18n

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2021 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

i18n is a simple package that translates strings using a language map. It mimicks some functionality of the vue-i18n library so that the same JSON language map may be used in the JS frontent 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 New

func New(b []byte) (*I18n, error)

New returns an I18n instance.

func (*I18n) Code

func (i *I18n) Code() string

Code returns the ISO code of the language.

func (*I18n) JSON

func (i *I18n) JSON() []byte

JSON returns the languagemap as raw JSON.

func (*I18n) Load

func (i *I18n) Load(b []byte) error

Load loads a JSON language map into the instance overwriting existing keys that conflict.

func (*I18n) Name

func (i *I18n) Name() string

Name returns the canonical name of the language.

func (*I18n) T

func (i *I18n) T(key string) string

T returns the translation for the given key similar to vue i18n's t().

func (*I18n) Tc

func (i *I18n) Tc(key string, n int) string

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

func (i *I18n) Ts(key string, params ...string) string

Ts returns the translation for the given key similar to vue i18n's t() and subsitutes 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)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL