Documentation ¶
Index ¶
- Variables
- func Bundle() error
- func Import(importer Importer, locale string, src io.Reader) error
- func ImportFile(importer Importer, fname string) error
- func ImportValue(value Value)
- func Locales() []string
- func TranslationPriority(locales ...string)
- func Validate() error
- type AndroidImporter
- type ErrArrayCountMismatch
- type ErrFormatSpecifierCountMismatch
- type ErrList
- type ErrMissingValue
- type ErrOtherMissing
- type ErrTypeMismatch
- type ErrUnexpectedAmountOfFormatSpecifiers
- type ErrVerbConflict
- type Importer
- type PluralBuilder
- type PrintfFormatSpecifier
- type Resources
- func (l *Resources) Keys() []string
- func (l *Resources) QuantityText(id string, quantity int, args ...interface{}) (string, error)
- func (l *Resources) Text(id string, args ...interface{}) (string, error)
- func (l *Resources) TextArray(id string) ([]string, error)
- func (l *Resources) Value(key string) Value
- type Value
Constants ¶
This section is empty.
Variables ¶
var ErrTextNotFound = fmt.Errorf("string not found")
ErrTextNotFound is the sentinel error for a named string which is not available
Functions ¶
func Bundle ¶
func Bundle() error
Bundle (re)generates all localizations in the current working directory.
func Import ¶
Import takes the importer and locale and updates the according internal localization resources. The order of import is relevant, because it determines the fallback matching logic. Import your default fallback language first.
func ImportFile ¶
ImportFile is a convenience method for Import. It detects the locale from the file name
func TranslationPriority ¶
func TranslationPriority(locales ...string)
TranslationPriority updates the resolution order and removes unwanted translations. "und" is the undefined default locale.
Types ¶
type AndroidImporter ¶
type AndroidImporter struct { }
An AndroidImporter supports the android strings xml format with simple strings, interpolation, indices, plurals and arrays. However, references and indices with more than 9 not.
type ErrArrayCountMismatch ¶
ErrArrayCountMismatch indicates that two arrays must have the same amount of entries
func (ErrArrayCountMismatch) Error ¶
func (e ErrArrayCountMismatch) Error() string
type ErrFormatSpecifierCountMismatch ¶
type ErrFormatSpecifierCountMismatch struct { Value0 Value Specs0 []PrintfFormatSpecifier Value1 Value Specs1 []PrintfFormatSpecifier }
ErrFormatSpecifierCountMismatch is used to indicates that the number printf formatting directives is different but they must be equal.
func (*ErrFormatSpecifierCountMismatch) Error ¶
func (e *ErrFormatSpecifierCountMismatch) Error() string
type ErrMissingValue ¶
ErrMissingValue contains an example value and the resources which is missing it
func (ErrMissingValue) Error ¶
func (e ErrMissingValue) Error() string
type ErrOtherMissing ¶
type ErrOtherMissing struct {
Value Value
}
ErrOtherMissing indicates a missing "other" value for a plural. You may omit everything else but other is the fallback and must not be empty at least.
func (ErrOtherMissing) Error ¶
func (e ErrOtherMissing) Error() string
type ErrTypeMismatch ¶
ErrTypeMismatch contains two Values of two different values which have different types, which is not allowed.
func (ErrTypeMismatch) Error ¶
func (e ErrTypeMismatch) Error() string
type ErrUnexpectedAmountOfFormatSpecifiers ¶
type ErrUnexpectedAmountOfFormatSpecifiers struct { Value Value Found int Expected int Text string }
ErrUnexpectedAmountOfFormatSpecifiers indicates that a value has an unexpected amount of specifiers. E.g. arrays must not contain any specifiers.
func (*ErrUnexpectedAmountOfFormatSpecifiers) Error ¶
func (e *ErrUnexpectedAmountOfFormatSpecifiers) Error() string
type ErrVerbConflict ¶
type ErrVerbConflict struct { Value0 Value Verb0 PrintfFormatSpecifier Value1 Value Verb1 PrintfFormatSpecifier }
ErrVerbConflict is returned, if two strings have different verb specifiers for the same position
func (*ErrVerbConflict) Error ¶
func (e *ErrVerbConflict) Error() string
type Importer ¶
type Importer interface { // Import tries to parse the src bytes and imports that into the given resources. Import(dst *Resources, src io.Reader) error }
An Importer parses data formats and imports that into resources.
type PluralBuilder ¶
type PluralBuilder interface { Value Zero(text string) PluralBuilder One(text string) PluralBuilder Two(text string) PluralBuilder Few(text string) PluralBuilder Many(text string) PluralBuilder Other(text string) PluralBuilder }
func NewQuantityText ¶
func NewQuantityText(locale string, id string) PluralBuilder
type PrintfFormatSpecifier ¶
type PrintfFormatSpecifier struct { Src string // Src is the entire string Pos int // Pos is the index in src where this specifier is located End int // End is the end index in src where this specifier is located Index int // Index is the argument position. Either this is the natural order or derived by the indexed position. PosIndex int // PosIndex is the positional index, which is the order as parsed }
PrintFormatSpecifier represents a part of a printf string, like %s, %[5]d or %10.10s.
func ParsePrintf ¶
func ParsePrintf(str string) []PrintfFormatSpecifier
ParsePrintf returns all found format specifiers and returns them in a sorted order by index position
func (*PrintfFormatSpecifier) String ¶
func (f *PrintfFormatSpecifier) String() string
String returns the entire format specifier
func (*PrintfFormatSpecifier) Verb ¶
func (f *PrintfFormatSpecifier) Verb() byte
Verb returns the single character and not the entire formatting directive.
type Resources ¶
type Resources struct {
// contains filtered or unexported fields
}
Resources is a type for accessing an applications text resources. It is safe to use concurrently.
func (*Resources) QuantityText ¶
QuantityText returns a translated and grammatically correct pluralization string or ErrTextNotFound
type Value ¶
type Value interface { ID() string // TextArray returns the backing strings array TextArray() ([]string, error) // Text formats the value with the given arguments Text(args ...interface{}) (string, error) // QuantityText formats the value with the given arguments QuantityText(quantity int, args ...interface{}) (string, error) // Locale returns the CLDR language tag Locale() string // contains filtered or unexported methods }
A Value is a contract which is implemented by each kind of message Value, like simple, array or plural.