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('Date & Datetime') %>

- +
@@ -9,18 +9,16 @@ - - - - - - - - - - - - + <% if @times: %> + <% for time in @times: %> + + + + + + + <% end %> + <% end %>
<%- @T('Type') %>
<%- @T('Datetime') %>
<%- @T('Date') %>
<%= time[1] %><%= time[3]%><%- @T('Reset') %>
@@ -35,11 +33,11 @@ - <% if @list: %> - <% for item in @list: %> + <% if @strings: %> + <% for item in @strings: %> <%= item[1] %> - + <%= item[3]%> <%- @T('Reset') %> diff --git a/app/models/locale.rb b/app/models/locale.rb index 534f8aa56..a17881b23 100644 --- a/app/models/locale.rb +++ b/app/models/locale.rb @@ -3,7 +3,7 @@ class Locale < ApplicationModel def self.load - url = 'http://localhost:3001/api/v1/locales' + url = 'https://i18n.zammad.com/api/v1/locales' result = UserAgent.get( url, diff --git a/app/models/translation.rb b/app/models/translation.rb index a944255f4..b6e36d2a6 100644 --- a/app/models/translation.rb +++ b/app/models/translation.rb @@ -28,12 +28,20 @@ load translations from online ) result.data.each {|translation| #puts translation.inspect - exists = Translation.where(:locale => translation['locale'], :source => translation['source']).first - if exists + + # handle case insensitive sql + exists = Translation.where(:locale => translation['locale'], :format => translation['format'], :source => translation['source']) + translaten = nil + exists.each {|item| + if item.source == translation['source'] + translaten = item + end + } + if translaten # verify if update is needed - exists.update_attributes(translation.symbolize_keys!) - exists.save + translaten.update_attributes(translation.symbolize_keys!) + translaten.save else Translation.create(translation.symbolize_keys!) end @@ -51,6 +59,7 @@ push translations to online def self.push(locale) + # only push changed translations translations = Translation.where(:locale => locale) translations_to_push = [] translations.each {|translation| @@ -61,7 +70,7 @@ push translations to online return true if translations_to_push.empty? #return translations_to_push - url = 'http://localhost:3001/api/v1/thanks_for_your_support' + url = 'https://i18n.zammad.com/api/v1/thanks_for_your_support' result = UserAgent.post( url, @@ -103,6 +112,7 @@ get list of translations item.source, item.target, item.target_initial, + item.format, ] list.push data else @@ -110,6 +120,7 @@ get list of translations item.id, item.source, item.target, + item.format, ] list.push data end @@ -121,22 +132,8 @@ get list of translations end end - timestamp_map_default = 'yyyy-mm-dd HH:MM' - timestamp_map = { - :de => 'dd.mm.yyyy HH:MM', - } - timestamp = timestamp_map[ locale.to_sym ] || timestamp_map_default - - date_map_default = 'yyyy-mm-dd' - date_map = { - :de => 'dd.mm.yyyy', - } - date = date_map[ locale.to_sym ] || date_map_default - return { - :list => list, - :timestampFormat => timestamp, - :dateFormat => date, + :list => list, } end