diff --git a/app/assets/javascripts/app/controllers/_channel/chat.coffee b/app/assets/javascripts/app/controllers/_channel/chat.coffee index 13dc61e3d..886705b07 100644 --- a/app/assets/javascripts/app/controllers/_channel/chat.coffee +++ b/app/assets/javascripts/app/controllers/_channel/chat.coffee @@ -94,7 +94,6 @@ class App.ChannelChatDesigner extends App.Controller # select tab tab.addClass('is-selected').siblings().removeClass('is-selected') - value = tab.attr('data-value') width = parseInt value, 10 diff --git a/app/assets/javascripts/app/controllers/widget/translation_inline.coffee b/app/assets/javascripts/app/controllers/widget/translation_inline.coffee index c33b03838..95354acb8 100644 --- a/app/assets/javascripts/app/controllers/widget/translation_inline.coffee +++ b/app/assets/javascripts/app/controllers/widget/translation_inline.coffee @@ -1,5 +1,9 @@ -class Widget +class Widget extends App.Controller constructor: -> + super + + # only admins can do this + return if !@isRole('Admin') # bind on key down # if ctrl+alt+t is pressed, enable translation_inline and fire ui:rerender @@ -14,11 +18,69 @@ class Widget ) enable: -> - App.Config.set( 'translation_inline', true ) + # load in collection if needed + meta = App.i18n.meta() + if !@mapLoaded && meta && meta.mapToLoad + @mapLoaded = true + App.Translation.refresh(meta.mapToLoad, {clear: true} ) + + # enable translation inline + App.Config.set('translation_inline', true) + + # rerender controllers App.Event.trigger('ui:rerender') + # observe if text has been translated + $('body') + .on '.translation', 'focus', (e) -> + element = $(e.target) + element.data 'before', element.html() + element + .on '.translation', 'blur', (e) => + element = $(e.target) + source = element.attr('title') + + # get new translation + translation_new = element.html() + translation_new = ('' + translation_new) + .replace(/<.+?>/g, '') + + # set new translation + element.html(translation_new) + + # update translation + return if element.data('before') is translation_new + App.Log.debug 'translation_inline', 'translate update', translation_new, 'before', element.data + element.data 'before', translation_new + + # update runtime translation mapString + App.i18n.setMap(source, translation_new) + + # replace rest in page + $(".translation[title='#{source}']").html(translation_new) + + # update permanent translation mapString + translation = App.Translation.findByAttribute('source', source) + if translation + translation.updateAttribute('target', translation_new) + else + translation = new App.Translation + translation.load( + locale: @locale + source: source + target: translation_new + ) + translation.save() + + element + disable: -> - App.Config.set( 'translation_inline', false ) + $('body').off('.translation') + + # disable translation inline + App.Config.set('translation_inline', false) + + # rerender controllers App.Event.trigger('ui:rerender') App.Config.set( 'translation_inline', Widget, 'Widgets' ) \ No newline at end of file diff --git a/app/assets/javascripts/app/lib/app_post/i18n.coffee b/app/assets/javascripts/app/lib/app_post/i18n.coffee index beda7b965..aef9cef14 100644 --- a/app/assets/javascripts/app/lib/app_post/i18n.coffee +++ b/app/assets/javascripts/app/lib/app_post/i18n.coffee @@ -89,50 +89,6 @@ class _i18nSingleton extends Spine.Module @dateFormat = 'yyyy-mm-dd' @timestampFormat = 'yyyy-mm-dd HH:MM' - # observe if text has been translated - $('body') - .delegate '.translation', 'focus', (e) -> - $this = $(e.target) - $this.data 'before', $this.html() - return $this - .delegate '.translation', 'blur', (e) => - $this = $(e.target) - source = $this.attr('title') - - # get new translation - translation_new = $this.html() - translation_new = ('' + translation_new) - .replace(/<.+?>/g, '') - - # set new translation - $this.html(translation_new) - - # update translation - return if $this.data('before') is translation_new - @log 'debug', 'translate Update', translation_new, $this.data, 'before' - $this.data 'before', translation_new - - # update runtime translation mapString - @mapString[source] = translation_new - - # replace rest in page - $(".translation[title='#{source}']").html(translation_new) - - # update permanent translation mapString - translation = App.Translation.findByAttribute('source', source) - if translation - translation.updateAttribute('target', translation_new) - else - translation = new App.Translation - translation.load( - locale: @locale - source: source - target: translation_new - ) - translation.save() - - return $this - get: -> @locale @@ -211,18 +167,18 @@ class _i18nSingleton extends Spine.Module mapToLoad.push item @mapMeta.translated = mapToLoad.length - - # load in collection if needed - if !_.isEmpty(mapToLoad) - App.Translation.refresh(mapToLoad, {clear: true} ) + @mapMeta.mapToLoad = mapToLoad App.Event.trigger('i18n:language:change') ) translateInline: (string, args) => + return string if !string App.Utils.htmlEscape(@translate(string, args)) translateContent: (string, args) => + return string if !string + if App.Config.get('translation_inline') return '' + App.Utils.htmlEscape(@translate(string)) + ''