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,17 +123,41 @@ class _i18nSingleton extends Spine.Module
get: ->
@locale
set: ( locale ) ->
set: ( localeToSet ) ->
# prepare locale
localeToSet = locale.toLowerCase()
localeToSet = localeToSet.toLowerCase()
# try aliases
# check if locale exists
localeFound = false
locales = App.Locale.all()
for locale in locales
if locale.alias is locale
if locale.locale is localeToSet
localeFound = true
# try aliases
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

View file

@ -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()