From 507fbeb068ac168868ef00bd1f40d3ba4d17c884 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Thu, 21 Jan 2016 10:07:29 -0300 Subject: Refactoring api to use translations (chunk 1) - Add spanish translations - Files in order by name from admin to export - Does not include api templates and tests - Fix web_test to load translations - Fix i18n to fallback to DEFAULT_LOCALE if no system locale found --- utils/i18n.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'utils/i18n.go') diff --git a/utils/i18n.go b/utils/i18n.go index 4fc8c725a..0f9b65617 100644 --- a/utils/i18n.go +++ b/utils/i18n.go @@ -36,7 +36,10 @@ func InitTranslations() { func GetTranslationsBySystemLocale() i18n.TranslateFunc { locale := model.DEFAULT_LOCALE if userLanguage, err := jibber_jabber.DetectLanguage(); err == nil { - locale = userLanguage + // only set the system locale if is supported, fallback to DEFAULT_LOCALE + if contains(userLanguage) { + locale = userLanguage + } } if locales[locale] == "" { @@ -138,3 +141,12 @@ 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 +} -- cgit v1.2.3-1-g7c22