i18n

package
v0.0.5-dev Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

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 different languages.

func New

func New() *I18n

New returns an empty I18n instance.

func (*I18n) JSON

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

JSON returns the languagemap as raw JSON.

func (*I18n) Load

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

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

func (*I18n) Name

func (i *I18n) Name(code string) string

Name returns the canonical name of the language.

func (*I18n) ParseLanguage

func (i *I18n) ParseLanguage(acceptLanguage string) string

ParseLanguage parses the language string and returns the locale code.

func (*I18n) T

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

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

func (*I18n) Tag

func (i *I18n) Tag(code string) language.Tag

Tag returns the language tag.

func (*I18n) Tc

func (i *I18n) Tc(code, 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(code, key string, params ...string) string

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", "notes",
"error", err)

Jump to

Keyboard shortcuts

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