bundle

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2017 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package bundle manages translations for multiple languages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bundle

type Bundle struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Bundle stores the translations for multiple languages.

func New

func New() *Bundle

New returns an empty bundle.

func (*Bundle) AddTranslation

func (b *Bundle) AddTranslation(lang *language.Language, translations ...translation.Translation)

AddTranslation adds translations for a language.

It is useful if your translations are in a format not supported by LoadTranslationFile.

func (*Bundle) LanguageTags added in v1.3.0

func (b *Bundle) LanguageTags() []string

LanguageTags returns the tags of all languages that that have been added.

func (*Bundle) LanguageTranslationIDs added in v1.3.0

func (b *Bundle) LanguageTranslationIDs(languageTag string) []string

LanguageTranslationIDs returns the ids of all translations that have been added for a given language.

func (*Bundle) LoadTranslationFile

func (b *Bundle) LoadTranslationFile(filename string) error

LoadTranslationFile loads the translations from filename into memory.

The language that the translations are associated with is parsed from the filename (e.g. en-US.json).

Generally you should load translation files once during your program's initialization.

func (*Bundle) MustLoadTranslationFile

func (b *Bundle) MustLoadTranslationFile(filename string)

MustLoadTranslationFile is similar to LoadTranslationFile except it panics if an error happens.

func (*Bundle) MustTfunc

func (b *Bundle) MustTfunc(pref string, prefs ...string) TranslateFunc

MustTfunc is similar to Tfunc except it panics if an error happens.

func (*Bundle) MustTfuncAndLanguage added in v1.1.0

func (b *Bundle) MustTfuncAndLanguage(pref string, prefs ...string) (TranslateFunc, *language.Language)

MustTfuncAndLanguage is similar to TfuncAndLanguage except it panics if an error happens.

func (*Bundle) ParseTranslationFileBytes

func (b *Bundle) ParseTranslationFileBytes(filename string, buf []byte) error

ParseTranslationFileBytes is similar to LoadTranslationFile except it parses the bytes in buf.

It is useful for parsing translation files embedded with go-bindata.

func (*Bundle) Tfunc

func (b *Bundle) Tfunc(pref string, prefs ...string) (TranslateFunc, error)

Tfunc is similar to TfuncAndLanguage except is doesn't return the Language.

func (*Bundle) TfuncAndLanguage added in v1.1.0

func (b *Bundle) TfuncAndLanguage(pref string, prefs ...string) (TranslateFunc, *language.Language, error)

TfuncAndLanguage returns a TranslateFunc for the first Language that has a non-zero number of translations in the bundle.

The returned Language matches the the first language preference that could be satisfied, but this may not strictly match the language of the translations used to satisfy that preference.

For example, the user may request "zh". If there are no translations for "zh" but there are translations for "zh-cn", then the translations for "zh-cn" will be used but the returned Language will be "zh".

It can parse languages from Accept-Language headers (RFC 2616), but it assumes weights are monotonically decreasing.

func (*Bundle) Translations

func (b *Bundle) Translations() map[string]map[string]translation.Translation

Translations returns all translations in the bundle.

type TranslateFunc

type TranslateFunc func(translationID string, args ...interface{}) string

TranslateFunc is a copy of i18n.TranslateFunc to avoid a circular dependency.

Jump to

Keyboard shortcuts

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