summaryrefslogtreecommitdiffstats
path: root/utils/i18n.go
diff options
context:
space:
mode:
authorElias Nahum <nahumhbl@gmail.com>2016-01-21 10:07:29 -0300
committerElias Nahum <nahumhbl@gmail.com>2016-01-21 10:14:02 -0300
commit507fbeb068ac168868ef00bd1f40d3ba4d17c884 (patch)
tree3743620af45c649352e04e2c86587b4dbb1f7ba7 /utils/i18n.go
parent9f526555df64885be27e38e588c23332d80cd208 (diff)
downloadchat-507fbeb068ac168868ef00bd1f40d3ba4d17c884.tar.gz
chat-507fbeb068ac168868ef00bd1f40d3ba4d17c884.tar.bz2
chat-507fbeb068ac168868ef00bd1f40d3ba4d17c884.zip
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
Diffstat (limited to 'utils/i18n.go')
-rw-r--r--utils/i18n.go14
1 files changed, 13 insertions, 1 deletions
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
+}