i18n

package
v0.0.0-...-fad53ba Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2018 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// Langs is the list of all loaded languages in the application
	Langs []string
)

Functions

func BootStrap

func BootStrap()

BootStrap initializes available languages

func LoadPOFile

func LoadPOFile(fileName string)

LoadPOFile load the file with the given filename into the Registry. This function is meant to be called several times to load all translations across all languages and modules. It panics in case of errors in the PO file.

func TranslateCode

func TranslateCode(lang, context, src string) string

TranslateCode returns the translation for the given src in the given lang, in the given context. If no translation is found or if the translation is the empty string src is returned.

func TranslateFieldDescription

func TranslateFieldDescription(lang, model, field, defaultValue string) string

TranslateFieldDescription returns the translation for the given model field name in the given lang, using the default translation Registry. If no translation is found or if the translation is the empty string defaultValue is returned.

func TranslateFieldHelp

func TranslateFieldHelp(lang, model, field, defaultValue string) string

TranslateFieldHelp returns the translation for the given model field help in the given lang, using the default translation Registry. If no translation is found or if the translation is the empty string defaultValue is returned.

func TranslateFieldSelection

func TranslateFieldSelection(lang, model, field string, selection types.Selection) types.Selection

TranslateFieldSelection returns the translated version of the given selection in the given lang, using the default translation Registry. When no translation is found for an item, the original string is used.

func TranslateResourceItem

func TranslateResourceItem(lang, resourceID, src string) string

TranslateResourceItem returns the translation for the given src of the given resource in the given lang using the default translation Registry. If no translation is found or if the translation is the empty string src is returned.

Types

type LangDirection

type LangDirection string

A LangDirection defines the direction of a language either left-to-right or right-to-left

const (
	// LangDirectionLTR defines a language written from left to right
	LangDirectionLTR LangDirection = "ltr"
	// LangDirectionRTL defines a language written from right to left
	LangDirectionRTL LangDirection = "rtl"
)

type LangParameters

type LangParameters struct {
	DateFormat   string        `json:"date_format"`
	Direction    LangDirection `json:"lang_direction"`
	ThousandsSep string        `json:"thousands_sep"`
	TimeFormat   string        `json:"time_format"`
	DecimalPoint string        `json:"decimal_point"`
	ID           int64         `json:"id"`
	Grouping     string        `json:"grouping"`
}

LangParameters defines the parameters of a language locale

type Translation

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

A Translation holds all the translations for a given language

type TranslationsCollection

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

A TranslationsCollection holds all the translations of the application

var Registry *TranslationsCollection

Registry holds all the translation of the application

func NewTranslationsCollection

func NewTranslationsCollection() *TranslationsCollection

NewTranslationsCollection returns a pointer to a new TranslationsCollection ready for use

func (*TranslationsCollection) LoadPOFile

func (tc *TranslationsCollection) LoadPOFile(fileName string)

LoadPOFile load the file with the given filename into the TranslationsCollection. This function can be called several times to iteratively load translations. It panics in case of errors in the PO file.

func (*TranslationsCollection) TranslateCode

func (tc *TranslationsCollection) TranslateCode(lang, context, src string) string

TranslateCode returns the translation for the given src in the given lang, in the given context. If no translation is found or if the translation is the empty string src is returned.

func (*TranslationsCollection) TranslateFieldDescription

func (tc *TranslationsCollection) TranslateFieldDescription(lang, model, field, defaultValue string) string

TranslateFieldDescription returns the translation for the given model field name in the given lang. If no translation is found or if the translation is the empty string defaultValue is returned.

func (*TranslationsCollection) TranslateFieldHelp

func (tc *TranslationsCollection) TranslateFieldHelp(lang, model, field, defaultValue string) string

TranslateFieldHelp returns the translation for the given model field help in the given lang. If no translation is found or if the translation is the empty string defaultValue is returned.

func (*TranslationsCollection) TranslateFieldSelection

func (tc *TranslationsCollection) TranslateFieldSelection(lang, model, field string, selection types.Selection) types.Selection

TranslateFieldSelection returns the translated version of the given selection in the given lang. When no translation is found for an item, the original string is used.

func (*TranslationsCollection) TranslateResourceItem

func (tc *TranslationsCollection) TranslateResourceItem(lang, resourceID, src string) string

TranslateResourceItem returns the translation for the given src of the given resource in the given lang. If no translation is found or if the translation is the empty string src is returned.

Jump to

Keyboard shortcuts

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