Documentation
¶
Index ¶
- func GetSupportedLocales() map[string]string
- func InitTranslations(serverLocale, clientLocale string) error
- func TranslateAsHTML(t TranslateFunc, translationID string, args map[string]any) template.HTML
- func TranslationsPreInit(translationsDir string) error
- type TranslateFunc
- type TranslationFuncByLocal
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetSupportedLocales ¶
GetSupportedLocales return a map of locale code and the file path with the translations
func InitTranslations ¶
InitTranslations set the defaults configured in the server and initialize the T function using the server default as fallback language
func TranslateAsHTML ¶
TranslateAsHTML translates the translationID provided and return a template.HTML object
func TranslationsPreInit ¶
TranslationsPreInit loads translations from filesystem if they are not loaded already and assigns english while loading server config
Types ¶
type TranslateFunc ¶
TranslateFunc is the type of the translate functions
var T TranslateFunc
T is the translate function using the default server language as fallback language
var TDefault TranslateFunc
TDefault is the translate function using english as fallback language
func GetTranslationsAndLocaleFromRequest ¶
func GetTranslationsAndLocaleFromRequest(r *http.Request) (TranslateFunc, string)
GetTranslationsAndLocaleFromRequest return the translation function and the locale based on a request headers
func GetTranslationsBySystemLocale ¶ added in v0.0.12
func GetTranslationsBySystemLocale() (TranslateFunc, error)
func GetUserTranslations ¶
func GetUserTranslations(locale string) TranslateFunc
GetUserTranslations get the translation function for an specific locale
func IdentityTfunc ¶
func IdentityTfunc() TranslateFunc
IdentityTfunc returns a translation function that don't translate, only returns the same id
type TranslationFuncByLocal ¶
type TranslationFuncByLocal func(locale string) TranslateFunc
TranslationFuncByLocal is the type of function that takes local as a string and returns the translation function
func GetTranslationFuncForDir ¶
func GetTranslationFuncForDir(dir string) (TranslationFuncByLocal, error)
GetTranslationFuncForDir loads translations from the filesystem into a new instance of the bundle. It returns a function to access loaded translations.