Deprecated: Use github.com/nicksnyder/go-i18n/v2 instead.

package bundle

import "github.com/nicksnyder/go-i18n/i18n/bundle"

Package bundle manages translations for multiple languages.

Index

Types

type Bundle

type Bundle struct {
	// 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) 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(languageSource string, languageSources ...string) TranslateFunc

MustTfunc is similar to Tfunc 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(src string, srcs ...string) (TranslateFunc, error)

Tfunc returns a TranslateFunc that will be bound to the first language which has a non-zero number of translations in the bundle.

It can parse languages from Accept-Language headers (RFC 2616).

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.

Source Files

bundle.go

Version
v1.0.0
Published
Apr 30, 2015
Platform
windows/amd64
Imports
6 packages
Last checked
2 hours ago

Tools for package owners.