Fixed locale detection.

This commit is contained in:
Martin Edenhofer 2015-05-03 22:56:21 +02:00
parent e7550ce169
commit b3aabfe379
2 changed files with 32 additions and 7 deletions

View file

@ -123,16 +123,40 @@ class _i18nSingleton extends Spine.Module
get: -> get: ->
@locale @locale
set: ( locale ) -> set: ( localeToSet ) ->
# prepare locale # 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 # try aliases
locales = App.Locale.all() if !localeFound
for locale in locales for locale in locales
if locale.alias is locale if locale.alias is localeToSet
localeToSet = locale.locale 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 # check if locale need to be changed
return if localeToSet is @locale return if localeToSet is @locale

View file

@ -54,7 +54,8 @@ test( "check pretty date", function() {
mm = '0' + mm mm = '0' + mm
} }
var yyyy = pastDate.getFullYear(); var yyyy = pastDate.getFullYear();
equal( result, yyyy+'-'+mm+'-'+dd, '30 days') // mm/dd/yyyy
equal( result, mm+'/'+dd+'/'+yyyy, '30 days')
// future // future
current = new Date() current = new Date()