Merge pull request #2007 from mattermost/PLT-7-server-fallback
PLT-7 Adding english fallback to server
Этот коммит содержится в:
@@ -44,7 +44,7 @@ func GetTranslationsBySystemLocale() i18n.TranslateFunc {
|
|||||||
panic("Failed to load system translations for '" + model.DEFAULT_LOCALE + "'")
|
panic("Failed to load system translations for '" + model.DEFAULT_LOCALE + "'")
|
||||||
}
|
}
|
||||||
|
|
||||||
translations, _ := i18n.Tfunc(locale)
|
translations := TfuncWithFallback(locale)
|
||||||
if translations == nil {
|
if translations == nil {
|
||||||
panic("Failed to load system translations")
|
panic("Failed to load system translations")
|
||||||
}
|
}
|
||||||
@@ -58,22 +58,34 @@ func GetUserTranslations(locale string) i18n.TranslateFunc {
|
|||||||
locale = model.DEFAULT_LOCALE
|
locale = model.DEFAULT_LOCALE
|
||||||
}
|
}
|
||||||
|
|
||||||
translations, _ := i18n.Tfunc(locale)
|
translations := TfuncWithFallback(locale)
|
||||||
return translations
|
return translations
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetTranslations(locale string) i18n.TranslateFunc {
|
func SetTranslations(locale string) i18n.TranslateFunc {
|
||||||
translations, _ := i18n.Tfunc(locale)
|
translations := TfuncWithFallback(locale)
|
||||||
return translations
|
return translations
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTranslationsAndLocale(w http.ResponseWriter, r *http.Request) (i18n.TranslateFunc, string) {
|
func GetTranslationsAndLocale(w http.ResponseWriter, r *http.Request) (i18n.TranslateFunc, string) {
|
||||||
headerLocale := strings.Split(strings.Split(r.Header.Get("Accept-Language"), ",")[0], "-")[0]
|
headerLocale := strings.Split(strings.Split(r.Header.Get("Accept-Language"), ",")[0], "-")[0]
|
||||||
if locales[headerLocale] != "" {
|
if locales[headerLocale] != "" {
|
||||||
translations, _ := i18n.Tfunc(headerLocale)
|
translations := TfuncWithFallback(headerLocale)
|
||||||
return translations, headerLocale
|
return translations, headerLocale
|
||||||
}
|
}
|
||||||
|
|
||||||
translations, _ := i18n.Tfunc(model.DEFAULT_LOCALE)
|
translations := TfuncWithFallback(model.DEFAULT_LOCALE)
|
||||||
return translations, model.DEFAULT_LOCALE
|
return translations, model.DEFAULT_LOCALE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
t, _ := i18n.Tfunc("en")
|
||||||
|
return t(translationID, args...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user