i18n

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2018 License: MIT Imports: 10 Imported by: 0

README

Go-I18N

Documentation

Index

Constants

View Source
const (
	// Prefix marks the begin of a placeholder being used for i18n interpolation
	Prefix = "{{"
	// Suffix marks the end of a placeholder being used for i18n interpolation
	Suffix = "}}"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Intermediate

type Intermediate string

func (Intermediate) Format

func (i Intermediate) Format() string

type Key

type Key string

func (Key) Append

func (k Key) Append(s string) Key

func (Key) String

func (k Key) String() string

type Language

type Language string

Language is the code abbreviation of language

func (Language) Valid

func (lang Language) Valid() bool

Valid verifies the validity of a language allowing only two letter codes

type Store

type Store map[Key]Translation

Store is a map where a key maps to a translation

type Translation

type Translation struct {
	Message       string
	Intermediates []Intermediate
}

type Translations

type Translations struct {
	// contains filtered or unexported fields
}

Translations are a collection of language translations represented by key value structure Upon translating it will attempt to retrieve the target language from a given source function, rolling back to the default language on failure. The translations are loaded during intialization from a defined directory

func NewTranslations

func NewTranslations(directory string, defaultLanguage string, languageFn func() string) Translations

NewTranslations initializes a new translations object

func (Translations) Load

func (trl Translations) Load() (Translations, error)

Load processes all language files of the defined directory and parses it into a kv structure keyed by the language code. It fetches all files in the directory using their base name as language identifier. The files are expected to be of JSON format. Load allows nested translations in the file meaning the key must not be denoted in a single form but can be splitted along the nesting levels (it follows the i18next standard). It will recursively summarize these keys into a full one, saving each value under the appropriate full key and return a flattened structure.

func (Translations) Translate

func (trl Translations) Translate(k string, params ...interface{}) (template.HTML, error)

Translate returns the appropriate translation for a given key, interpolating the passed parameter values assuming the intermediates match the parameter keys injectively.

Jump to

Keyboard shortcuts

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