universal-translator – github.com/go-playground/universal-translator Index | Files | Directories

package ut

import "github.com/go-playground/universal-translator"

Index

Variables

var (
	// ErrUnknowTranslation indicates the translation could not be found
	ErrUnknowTranslation = errors.New("Unknown Translation")
)

Types

type ErrCardinalTranslation

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

ErrCardinalTranslation is the error representing a cardinal translation error

func (*ErrCardinalTranslation) Error

func (e *ErrCardinalTranslation) Error() string

Error returns ErrCardinalTranslation's internal error text

type ErrConflictingTranslation

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

ErrConflictingTranslation is the error representing a conflicting translation

func (*ErrConflictingTranslation) Error

func (e *ErrConflictingTranslation) Error() string

Error returns ErrConflictingTranslation's internal error text

type ErrLocaleNotFound

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

ErrLocaleNotFound is the error signifying a locale which could not be found

func (*ErrLocaleNotFound) Error

func (e *ErrLocaleNotFound) Error() string

Error returns ErrLocaleNotFound's internal error text

type ErrMissingPluralTranslation

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

ErrMissingPluralTranslation is the error signifying a missing translation given the locales plural rules.

func (*ErrMissingPluralTranslation) Error

Error returns ErrMissingPluralTranslation's internal error text

type ErrOrdinalTranslation

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

ErrOrdinalTranslation is the error representing an ordinal translation error

func (*ErrOrdinalTranslation) Error

func (e *ErrOrdinalTranslation) Error() string

Error returns ErrOrdinalTranslation's internal error text

type ErrRangeTranslation

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

ErrRangeTranslation is the error representing a range translation error

func (*ErrRangeTranslation) Error

func (e *ErrRangeTranslation) Error() string

Error returns ErrRangeTranslation's internal error text

type Translator

type Translator interface {
	locales.Translator

	// adds a normal translation for a particular language/locale
	// {#} is the only replacement type accepted and are add infintium
	// eg. one: '{0} day left' other: '{0} days left'
	Add(key interface{}, text string) error

	// is the same as Add only it allows existing translations to be overridden
	Overwrite(key interface{}, text string) error

	// adds a cardinal plural translation for a particular language/locale
	// {0} is the only replacement type accepted and only one variable is accepted as
	// multiple cannot be used for a plural rule determination, unless it is a range;
	// see AddRange below.
	// eg. in locale 'en' one: '{0} day left' other: '{0} days left'
	AddCardinal(key interface{}, text string, rule locales.PluralRule) error

	// is the same as AddCardinal only it allows existing translations to be overridden
	OverwriteCardinal(key interface{}, text string, rule locales.PluralRule) error

	// adds an ordinal plural translation for a particular language/locale
	// {0} is the only replacement type accepted and only one variable is accepted as
	// multiple cannot be used for a plural rule determination, unless it is a range;
	// see AddRange below.
	// eg. in locale 'en' one: '{0}st day of spring' other: '{0}nd day of spring'
	// - 1st, 2nd, 3rd...
	AddOrdinal(key interface{}, text string, rule locales.PluralRule) error

	// is the same as AddOrdinal only it allows for existing translations to be overridden
	OverwriteOrdinal(key interface{}, text string, rule locales.PluralRule) error

	// adds a range plural translation for a particular language/locale
	// {0} and {1} are the only replacement types accepted and only these are accepted.
	// eg. in locale 'nl' one: '{0}-{1} day left' other: '{0}-{1} days left'
	AddRange(key interface{}, text string, rule locales.PluralRule) error

	// is the same as AddRange only allows an existing translation to be overridden
	OverwriteRange(key interface{}, text string, rule locales.PluralRule) error

	// creates the translation for the locale given the 'key' and params passed in
	T(key interface{}, params ...string) string

	// creates the cardinal translation for the locale given the 'key', 'num' and 'digit' arguments
	//  and param passed in
	C(key interface{}, num float64, digits uint64, param string) (string, error)

	// creates the ordinal translation for the locale given the 'key', 'num' and 'digit' arguments
	// and param passed in
	O(key interface{}, num float64, digits uint64, param string) (string, error)

	//  creates the range translation for the locale given the 'key', 'num1', 'digit1', 'num2' and
	//  'digit2' arguments and 'param1' and 'param2' passed in
	R(key interface{}, num1 float64, digits1 uint64, num2 float64, digits2 uint64, param1, param2 string) (string, error)

	// VerifyTranslations checks to ensures that no plural rules have been
	// missed within the translations.
	VerifyTranslations() error
}

Translator is universal translators translator instance which is a thin wrapper around locales.Translator instance providing some extra functionality

type UniversalTranslator

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

UniversalTranslator holds all locale & translation data

func New

func New(fallback string, supportedLocales ...string) (*UniversalTranslator, error)

New returns a new UniversalTranslator instance set with the fallback locale and locales it should support

func (*UniversalTranslator) FindTranslator

func (t *UniversalTranslator) FindTranslator(locales ...string) (trans Translator)

FindTranslator trys to find a Translator based on an array of locales and returns the first one it can find, otherwise returns the fallback translator.

func (*UniversalTranslator) GetTranslator

func (t *UniversalTranslator) GetTranslator(locale string) Translator

GetTranslator returns the specified translator for the given locale, or fallback if not found

Source Files

errors.go translator.go universal-translator.go

Directories

PathSynopsis
examples
examples/basic
Version
v0.10.0
Published
Aug 29, 2016
Platform
js/wasm
Imports
6 packages
Last checked
now

Tools for package owners.