summaryrefslogtreecommitdiffstats
path: root/utils/i18n.go
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2016-01-28 09:51:37 -0500
committer=Corey Hulen <corey@hulen.com>2016-01-28 09:51:37 -0500
commitc7c30a063da5c45a66b0447c07c0089379c5a99b (patch)
treec5e561536c00abc5c517bc9805c06df2d86d5698 /utils/i18n.go
parentc7d9754f4b8ce8eefb0c9608cf6c2cec2a7d44fe (diff)
downloadchat-c7c30a063da5c45a66b0447c07c0089379c5a99b.tar.gz
chat-c7c30a063da5c45a66b0447c07c0089379c5a99b.tar.bz2
chat-c7c30a063da5c45a66b0447c07c0089379c5a99b.zip
Adding english fallback
Diffstat (limited to 'utils/i18n.go')
-rw-r--r--utils/i18n.go18
1 files changed, 10 insertions, 8 deletions
diff --git a/utils/i18n.go b/utils/i18n.go
index d545d18b8..e809ae883 100644
--- a/utils/i18n.go
+++ b/utils/i18n.go
@@ -44,7 +44,7 @@ func GetTranslationsBySystemLocale() i18n.TranslateFunc {
panic("Failed to load system translations for '" + model.DEFAULT_LOCALE + "'")
}
- translations, _ := TfuncWithFallback(locale)
+ translations := TfuncWithFallback(locale)
if translations == nil {
panic("Failed to load system translations")
}
@@ -58,32 +58,34 @@ func GetUserTranslations(locale string) i18n.TranslateFunc {
locale = model.DEFAULT_LOCALE
}
- translations, _ := TfuncWithFallback(locale)
+ translations := TfuncWithFallback(locale)
return translations
}
func SetTranslations(locale string) i18n.TranslateFunc {
- translations, _ := TfuncWithFallback(locale)
+ translations := TfuncWithFallback(locale)
return translations
}
func GetTranslationsAndLocale(w http.ResponseWriter, r *http.Request) (i18n.TranslateFunc, string) {
headerLocale := strings.Split(strings.Split(r.Header.Get("Accept-Language"), ",")[0], "-")[0]
if locales[headerLocale] != "" {
- translations, _ := TfuncWithFallback(headerLocale)
+ translations := TfuncWithFallback(headerLocale)
return translations, headerLocale
}
- translations, _ := TfuncWithFallback(model.DEFAULT_LOCALE)
+ translations := TfuncWithFallback(model.DEFAULT_LOCALE)
return translations, model.DEFAULT_LOCALE
}
-func TfuncWithFallback(pref string, prefs ...string) TranslateFunc {
- t := i18n.MustTfunc(pref, prefs...)
+func TfuncWithFallback(pref string) i18n.TranslateFunc {
+ t, _ := i18n.Tfunc(pref)
return func(translationID string, args ...interface{}) string {
if translated := t(translationID, args...); translated != translationID {
return translated
}
- return i18n.MustTfunc("en", args...)
+
+ t, _ := i18n.Tfunc("en")
+ return t(translationID, args...)
}
}