For rtl support in js we need to know what direction it is.

This commit is contained in:
Martin Edenhofer 2017-07-28 11:45:58 +02:00
parent a222a0878f
commit d1b50e0ed2

View file

@ -30,6 +30,11 @@ class App.i18n
_instance ?= new _i18nSingleton() _instance ?= new _i18nSingleton()
_instance.date(args, offset) _instance.date(args, offset)
@dir: ->
if _instance == undefined
_instance ?= new _i18nSingleton()
_instance.dir()
@get: -> @get: ->
if _instance == undefined if _instance == undefined
_instance ?= new _i18nSingleton() _instance ?= new _i18nSingleton()
@ -88,6 +93,10 @@ class _i18nSingleton extends Spine.Module
@_notTranslated = {} @_notTranslated = {}
@dateFormat = 'yyyy-mm-dd' @dateFormat = 'yyyy-mm-dd'
@timestampFormat = 'yyyy-mm-dd HH:MM' @timestampFormat = 'yyyy-mm-dd HH:MM'
@dirToSet = 'ltr'
dir: ->
@dirToSet
get: -> get: ->
@locale @locale
@ -96,7 +105,7 @@ class _i18nSingleton extends Spine.Module
# prepare locale # prepare locale
localeToSet = localeToSet.toLowerCase() localeToSet = localeToSet.toLowerCase()
dirToSet = 'ltr' @dirToSet = 'ltr'
# check if locale exists # check if locale exists
localeFound = false localeFound = false
@ -104,7 +113,7 @@ class _i18nSingleton extends Spine.Module
for locale in locales for locale in locales
if locale.locale is localeToSet if locale.locale is localeToSet
localeToSet = locale.locale localeToSet = locale.locale
dirToSet = locale.dir @dirToSet = locale.dir
localeFound = true localeFound = true
# try aliases # try aliases
@ -112,7 +121,7 @@ class _i18nSingleton extends Spine.Module
for locale in locales for locale in locales
if locale.alias is localeToSet if locale.alias is localeToSet
localeToSet = locale.locale localeToSet = locale.locale
dirToSet = locale.dir @dirToSet = locale.dir
localeFound = true localeFound = true
# if no locale and no alias was found, try to find correct one # if no locale and no alias was found, try to find correct one
@ -123,7 +132,7 @@ class _i18nSingleton extends Spine.Module
for locale in locales for locale in locales
if locale.alias is localeToSet if locale.alias is localeToSet
localeToSet = locale.locale localeToSet = locale.locale
dirToSet = locale.dir @dirToSet = locale.dir
localeFound = true localeFound = true
# check if locale need to be changed # check if locale need to be changed
@ -137,7 +146,7 @@ class _i18nSingleton extends Spine.Module
# set lang and dir attribute of html tag # set lang and dir attribute of html tag
$('html').prop('lang', localeToSet.substr(0, 2)) $('html').prop('lang', localeToSet.substr(0, 2))
$('html').prop('dir', dirToSet) $('html').prop('dir', @dirToSet)
@mapString = {} @mapString = {}
App.Ajax.request( App.Ajax.request(