diff --git a/app/assets/javascripts/app/controllers/translation.js.coffee b/app/assets/javascripts/app/controllers/translation.js.coffee index b1f29569c..541045dd6 100644 --- a/app/assets/javascripts/app/controllers/translation.js.coffee +++ b/app/assets/javascripts/app/controllers/translation.js.coffee @@ -80,7 +80,10 @@ class TranslationToDo extends App.Controller # local update App.i18n.removeNotTranslated( @locale, source ) - App.i18n.setMap( source, target ) + + # update runtime if same language is used + if App.i18n.get() is @locale + App.i18n.setMap( source, target, 'string' ) # remote update params = @@ -109,7 +112,10 @@ class TranslationToDo extends App.Controller # local update App.i18n.removeNotTranslated( @locale, source ) - App.i18n.setMap( source, source ) + + # update runtime if same language is used + if App.i18n.get() is @locale + App.i18n.setMap( source, source, 'string' ) # remote update params = @@ -157,10 +163,17 @@ class TranslationList extends App.Controller #if !App.i18n.notTranslatedFeatureEnabled(@locale) # return + @strings = [] + @times = [] + for item in data.list + if item[4] is 'time' + @times.push item + else + @strings.push item + @html App.view('translation/list')( - list: data.list - timestampFormat: data.timestampFormat - dateFormat: data.dateFormat + times: @times + strings: @strings ) ui = @ @$('.js-Item').each( (e) -> @@ -174,11 +187,19 @@ class TranslationList extends App.Controller id = field.data('id') source = field.data('source') initial = field.data('initial') + format = field.data('format') # if it's translated by user it self, delete it if !initial || initial is '' + + # locale reset $(e.target).closest('tr').remove() - App.i18n.setMap( source, '' ) + + # update runtime if same language is used + if App.i18n.get() is @locale + App.i18n.setMap( source, '', format ) + + # remote reset params = id: id @ajax( @@ -188,17 +209,21 @@ class TranslationList extends App.Controller data: JSON.stringify(params) processData: false success: => - console.log('aaa', @locale, source) App.i18n.setNotTranslated( @locale, source ) App.Event.trigger('i18n:translation_todo_reload') ) return - # update item - App.i18n.setMap( source, initial ) + # update runtime if same language is used + if App.i18n.get() is @locale + App.i18n.setMap( source, initial, format ) + + # locale reset field.val( initial ) @updateRow(id) + + # remote reset params = id: id target: initial @@ -215,11 +240,15 @@ class TranslationList extends App.Controller e.preventDefault() id = $( e.target ).data('id') source = $( e.target ).data('source') + format = $( e.target ).data('format') target = $( e.target ).val() - @updateRow(id) # local update - App.i18n.setMap( source, target ) + @updateRow(id) + + # update runtime if same language is used + if App.i18n.get() is @locale + App.i18n.setMap( source, target, format ) # remote update params = 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 569b15429..0a9eec249 100644 --- a/app/assets/javascripts/app/lib/app_post/i18n.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/i18n.js.coffee @@ -39,10 +39,10 @@ class App.i18n _instance ?= new _i18nSingleton() _instance.set( args ) - @setMap: (source, target) -> + @setMap: (source, target, format) -> if _instance == undefined _instance ?= new _i18nSingleton() - _instance.setMap( source, target ) + _instance.setMap( source, target, format ) @notTranslatedFeatureEnabled: (locale) -> if _instance == undefined @@ -68,7 +68,8 @@ class _i18nSingleton extends Spine.Module @include App.LogInclude constructor: ( locale ) -> - @map = {} + @mapTime = {} + @mapString = {} @_notTranslatedLog = false @_notTranslated = {} @dateFormat = 'yyyy-mm-dd' @@ -98,13 +99,13 @@ class _i18nSingleton extends Spine.Module @log 'debug', 'translate Update', translation_new, $this.data, 'before' $this.data 'before', translation_new - # update runtime translation map - @map[ source ] = translation_new + # update runtime translation mapString + @mapString[ source ] = translation_new # replace rest in page $(".translation[data-text='#{source}']").html( translation_new ) - # update permanent translation map + # update permanent translation mapString translation = App.Translation.findByAttribute( 'source', source ) if translation translation.updateAttribute( 'target', translation_new ) @@ -133,7 +134,7 @@ class _i18nSingleton extends Spine.Module # set lang attribute of html tag $('html').prop( 'lang', locale.substr(0, 2) ) - @map = {} + @mapString = {} App.Ajax.request( id: 'i18n-set-' + locale, type: 'GET', @@ -141,22 +142,20 @@ class _i18nSingleton extends Spine.Module async: false, success: (data, status, xhr) => - # set timestamp format - if data.timestampFormat - @timestampFormat = data.timestampFormat - - # set date format - if data.dateFormat - @dateFormat = data.dateFormat - # load translation collection for object in data.list - # set runtime lookup table - @map[ object[1] ] = object[2] + # set date/timestamp format + if object[3] is 'time' + @mapTime[ object[1] ] = object[2] - # load in collection if needed - App.Translation.refresh( { id: object[0], source: object[1], target: object[2], locale: @locale } ) + else + + # set runtime lookup table + @mapString[ object[1] ] = object[2] + + # load in collection if needed + App.Translation.refresh( { id: object[0], source: object[1], target: object[2], locale: @locale } ) ) translateInline: ( string, args... ) => @@ -188,9 +187,9 @@ class _i18nSingleton extends Spine.Module return '' if string is '' # return translation - if @map[string] isnt undefined + if @mapString[string] isnt undefined @_translated = true - translated = @map[string] + translated = @mapString[string] else @_translated = false translated = string @@ -209,8 +208,11 @@ class _i18nSingleton extends Spine.Module # return translated string return translated - setMap: ( source, target ) => - @map[source] = target + setMap: ( source, target, format = 'string' ) => + if format is 'time' + @mapTime[source] = target + else + @mapString[source] = target notTranslatedFeatureEnabled: (locale) => if locale.substr(0,2) is 'en' @@ -227,10 +229,10 @@ class _i18nSingleton extends Spine.Module @_notTranslated[locale][key] = true date: ( time, offset ) => - @convert(time, offset, @dateFormat) + @convert(time, offset, @mapTime['date'] || @dateFormat) timestamp: ( time, offset ) => - @convert(time, offset, @timestampFormat) + @convert(time, offset, @mapTime['timestamp'] || @timestampFormat) convert: ( time, offset, format ) => s = ( num, digits ) -> diff --git a/app/assets/javascripts/app/views/translation/list.jst.eco b/app/assets/javascripts/app/views/translation/list.jst.eco index 6c442d24a..407537d94 100644 --- a/app/assets/javascripts/app/views/translation/list.jst.eco +++ b/app/assets/javascripts/app/views/translation/list.jst.eco @@ -1,5 +1,5 @@
<%- @T('Type') %> | @@ -9,18 +9,16 @@|||
---|---|---|---|
<%- @T('Datetime') %> | -- | - | - |
<%- @T('Date') %> | -- | - | - |
<%= time[1] %> | ++ | <%= time[3]%> | +<%- @T('Reset') %> | +