Documentation ¶
Overview ¶
Package translations introduces a simple localization layer that can be used by a templating engine.
Upon retrieving a localization package, values can be retrieved in both Go code and the .html files via Get(key string). If a given key hasn't been translated, the default localization pack will be accessed.
If the templating engine accesses non existent values, the server will panic. This makes sure that we can't oversee the use of non-existent values.
Values must be plain text and not contain any HTML or CSS. If values are to be inserted dynamically, placeholders can be placed with "%s".
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterTranslation ¶
func RegisterTranslation(locale string, translation Translation)
RegisterTranslation makes adds a language to the registry and makes it available via Get. If the language is already registered, the server panics. This happens on startup, therefore it's safe.
Types ¶
type Translation ¶
Translation represents key - value pairs of translated user interface strings.
var DefaultTranslation Translation
DefaultTranslation is the fallback translation for cases where the users preferred language can't be found. This value is never returned by Get, but has to be retrieved manually if desired. Currently, this is en-US.
func GetLanguage ¶
func GetLanguage(locale string) Translation
GetLanguage retrieves a translation pack or nil if the desired package couldn't be found.
func (Translation) Get ¶
func (translation Translation) Get(key string) string
Get retrieves a translated string or the default string if none could be found.