From b3aabfe3798ed838ea02a7ebda93f1aa928b9c71 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 3 May 2015 22:56:21 +0200 Subject: [PATCH] Fixed locale detection. --- .../app/lib/app_post/i18n.js.coffee | 36 +++++++++++++++---- public/assets/tests/ui.js | 3 +- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/app/lib/app_post/i18n.js.coffee b/app/assets/javascripts/app/lib/app_post/i18n.js.coffee index 8f7dc91b7..fe8d8248c 100644 --- a/app/assets/javascripts/app/lib/app_post/i18n.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/i18n.js.coffee @@ -123,16 +123,40 @@ class _i18nSingleton extends Spine.Module get: -> @locale - set: ( locale ) -> + set: ( localeToSet ) -> # prepare locale - localeToSet = locale.toLowerCase() + localeToSet = localeToSet.toLowerCase() + + # check if locale exists + localeFound = false + locales = App.Locale.all() + for locale in locales + if locale.locale is localeToSet + localeFound = true # try aliases - locales = App.Locale.all() - for locale in locales - if locale.alias is locale - localeToSet = locale.locale + if !localeFound + for locale in locales + if locale.alias is localeToSet + localeToSet = locale.locale + + # if no locale and no alias was found, try to find correct one + if !localeFound + + # try to find by alias + localeToSet = localeToSet.substr(0, 2) + for locale in locales + if locale.alias is localeToSet + localeToSet = locale.locale + localeFound = true + + # try to find by locale + if !localeFound + for locale in locales + if locale.locale is localeToSet + localeToSet = locale.locale + localeFound = true # check if locale need to be changed return if localeToSet is @locale diff --git a/public/assets/tests/ui.js b/public/assets/tests/ui.js index 35da3e8c5..cb7297236 100644 --- a/public/assets/tests/ui.js +++ b/public/assets/tests/ui.js @@ -54,7 +54,8 @@ test( "check pretty date", function() { mm = '0' + mm } var yyyy = pastDate.getFullYear(); - equal( result, yyyy+'-'+mm+'-'+dd, '30 days') + // mm/dd/yyyy + equal( result, mm+'/'+dd+'/'+yyyy, '30 days') // future current = new Date()