summaryrefslogtreecommitdiffstats
path: root/utils/i18n.go
diff options
context:
space:
mode:
authorElias Nahum <nahumhbl@gmail.com>2016-01-21 12:30:14 -0300
committerElias Nahum <nahumhbl@gmail.com>2016-01-21 12:30:14 -0300
commitc8d22ed1fba591e7a6b18afc5e6a6d541c11645c (patch)
tree9e965f384b927fa552627f455db9b24cacb3e9ae /utils/i18n.go
parentaa68caa8f043008728ddd0cb34c9bcd29fd9638a (diff)
downloadchat-c8d22ed1fba591e7a6b18afc5e6a6d541c11645c.tar.gz
chat-c8d22ed1fba591e7a6b18afc5e6a6d541c11645c.tar.bz2
chat-c8d22ed1fba591e7a6b18afc5e6a6d541c11645c.zip
Fix bug to load the default locale if no system locale is found
Diffstat (limited to 'utils/i18n.go')
-rw-r--r--utils/i18n.go23
1 files changed, 6 insertions, 17 deletions
diff --git a/utils/i18n.go b/utils/i18n.go
index 0f9b65617..4b7b187a8 100644
--- a/utils/i18n.go
+++ b/utils/i18n.go
@@ -36,18 +36,16 @@ func InitTranslations() {
func GetTranslationsBySystemLocale() i18n.TranslateFunc {
locale := model.DEFAULT_LOCALE
if userLanguage, err := jibber_jabber.DetectLanguage(); err == nil {
- // only set the system locale if is supported, fallback to DEFAULT_LOCALE
- if contains(userLanguage) {
+ if _, ok := locales[userLanguage]; ok {
locale = userLanguage
+ } else {
+ l4g.Error("Failed to load system translations for '%v' attempting to fall back to '%v'", locale, model.DEFAULT_LOCALE)
+ locale = model.DEFAULT_LOCALE
}
}
- if locales[locale] == "" {
- l4g.Error("Failed to load system translations for '%v' attempting to fall back to '%v'", locale, model.DEFAULT_LOCALE)
-
- if locales[model.DEFAULT_LOCALE] == "" {
- panic("Failed to load system translations for '" + model.DEFAULT_LOCALE + "'")
- }
+ if locales[model.DEFAULT_LOCALE] == "" {
+ panic("Failed to load system translations for '" + model.DEFAULT_LOCALE + "'")
}
translations, _ := i18n.Tfunc(locale)
@@ -141,12 +139,3 @@ func getTranslationsAndLocale(w http.ResponseWriter, r *http.Request) (i18n.Tran
SetLocaleCookie(w, model.DEFAULT_LOCALE, 10)
return translations, model.DEFAULT_LOCALE
}
-
-func contains(l string) bool {
- for _, a := range locales {
- if a == l {
- return true
- }
- }
- return false
-}