summaryrefslogtreecommitdiffstats
path: root/utils/i18n.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2016-05-27 09:01:35 -0400
committerChristopher Speller <crspeller@gmail.com>2016-05-27 09:01:35 -0400
commitec7a273550a1aaf31e80abc90c99d06a94664b5d (patch)
treebd0d1080a5ef66b9e7985682919b1c2bd21d4bf1 /utils/i18n.go
parenta2c183f401bdf8e9abddd35d4561d42034325046 (diff)
downloadchat-ec7a273550a1aaf31e80abc90c99d06a94664b5d.tar.gz
chat-ec7a273550a1aaf31e80abc90c99d06a94664b5d.tar.bz2
chat-ec7a273550a1aaf31e80abc90c99d06a94664b5d.zip
Revert "PLT-1800 Load server side locale from the config.json" (#3133)
Diffstat (limited to 'utils/i18n.go')
-rw-r--r--utils/i18n.go32
1 files changed, 12 insertions, 20 deletions
diff --git a/utils/i18n.go b/utils/i18n.go
index 300f5ca7c..2503cd500 100644
--- a/utils/i18n.go
+++ b/utils/i18n.go
@@ -7,17 +7,15 @@ import (
"strings"
l4g "github.com/alecthomas/log4go"
- //"github.com/cloudfoundry/jibber_jabber"
+ "github.com/cloudfoundry/jibber_jabber"
"github.com/mattermost/platform/model"
"github.com/nicksnyder/go-i18n/i18n"
)
var T i18n.TranslateFunc
var locales map[string]string = make(map[string]string)
-var settings model.LocalizationSettings
-func InitTranslations(localizationSettings model.LocalizationSettings) {
- settings = localizationSettings
+func InitTranslations() {
InitTranslationsWithDir("i18n")
}
@@ -36,10 +34,14 @@ func InitTranslationsWithDir(dir string) {
}
func GetTranslationsBySystemLocale() i18n.TranslateFunc {
- locale := *settings.DefaultServerLocale
- if _, ok := locales[locale]; !ok {
- l4g.Error("Failed to load system translations for '%v' attempting to fall back to '%v'", locale, model.DEFAULT_LOCALE)
- locale = model.DEFAULT_LOCALE
+ locale := model.DEFAULT_LOCALE
+ if userLanguage, err := jibber_jabber.DetectLanguage(); err == nil {
+ 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] == "" {
@@ -70,20 +72,10 @@ func SetTranslations(locale string) i18n.TranslateFunc {
}
func GetTranslationsAndLocale(w http.ResponseWriter, r *http.Request) (i18n.TranslateFunc, string) {
- // This is for checking against locales like pt_BR or zn_CN
- headerLocaleFull := strings.Split(r.Header.Get("Accept-Language"), ",")[0]
- // This is for checking agains locales like en, es
headerLocale := strings.Split(strings.Split(r.Header.Get("Accept-Language"), ",")[0], "-")[0]
- defaultLocale := *settings.DefaultClientLocale
- if locales[headerLocaleFull] != "" {
- translations := TfuncWithFallback(headerLocaleFull)
- return translations, headerLocaleFull
- } else if locales[headerLocale] != "" {
+ if locales[headerLocale] != "" {
translations := TfuncWithFallback(headerLocale)
return translations, headerLocale
- } else if locales[defaultLocale] != "" {
- translations := TfuncWithFallback(defaultLocale)
- return translations, headerLocale
}
translations := TfuncWithFallback(model.DEFAULT_LOCALE)
@@ -97,7 +89,7 @@ func TfuncWithFallback(pref string) i18n.TranslateFunc {
return translated
}
- t, _ := i18n.Tfunc(model.DEFAULT_LOCALE)
+ t, _ := i18n.Tfunc("en")
return t(translationID, args...)
}
}