diff --git a/app/assets/javascripts/app/controllers/translation.coffee b/app/assets/javascripts/app/controllers/translation.coffee index 30e86fd88..1d7ec1afb 100644 --- a/app/assets/javascripts/app/controllers/translation.coffee +++ b/app/assets/javascripts/app/controllers/translation.coffee @@ -180,8 +180,12 @@ class Index extends App.ControllerContent delete params.field if params.id - method = 'PUT' - url = "#{@apiPath}/translations/#{params.id}" + if params.target is '' + method = 'DELETE' + url = "#{@apiPath}/translations/#{params.id}" + else + method = 'PUT' + url = "#{@apiPath}/translations/#{params.id}" else method = 'POST' url = "#{@apiPath}/translations" diff --git a/app/assets/javascripts/app/controllers/widget/translation_inline.coffee b/app/assets/javascripts/app/controllers/widget/translation_inline.coffee index d131adb0d..ffca5ff16 100644 --- a/app/assets/javascripts/app/controllers/widget/translation_inline.coffee +++ b/app/assets/javascripts/app/controllers/widget/translation_inline.coffee @@ -1,22 +1,32 @@ class Widget extends App.Controller constructor: -> super + @rebind() + App.Event.bind('auth', => @rebind()) + App.Event.bind('i18n:inline_translation', => @toogle()) + + rebind: => + $(document).off('keydown.translation') # 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 - $(document).on('keydown', (e) => + $(document).on('keydown.translation', (e) => if e.altKey && e.ctrlKey && e.keyCode is 84 - if @active - @disable() - @active = false - else - @enable() - @active = true + @toogle() ) + toogle: => + if @active + @disable() + @active = false + return + + @enable() + @active = true + enable: -> # load in collection if needed meta = App.i18n.meta() @@ -37,7 +47,6 @@ class Widget extends App.Controller element.data 'before', element.text() element .on 'blur.translation', '.translation', (e) -> - console.log('blur') element = $(e.target) source = element.attr('title') @@ -65,7 +74,7 @@ class Widget extends App.Controller locale: App.i18n.get() source: source target: translation_new - initial_target: '' + target_initial: '' ) translation.save() @@ -80,4 +89,4 @@ class Widget extends App.Controller # rerender controllers App.Event.trigger('ui:rerender') -App.Config.set( 'translation_inline', Widget, 'Widgets' ) \ No newline at end of file +App.Config.set('translation_inline', Widget, 'Widgets') diff --git a/app/assets/javascripts/app/lib/app_post/auth.coffee b/app/assets/javascripts/app/lib/app_post/auth.coffee index 1c08daa2a..72d401a6b 100644 --- a/app/assets/javascripts/app/lib/app_post/auth.coffee +++ b/app/assets/javascripts/app/lib/app_post/auth.coffee @@ -63,11 +63,11 @@ class App.Auth # update config for key, value of data.config - App.Config.set( key, value ) + App.Config.set(key, value) # refresh default collections if data.collections - App.Collection.resetCollections( data.collections ) + App.Collection.resetCollections(data.collections) # empty session App.Session.init() @@ -81,18 +81,18 @@ class App.Auth # set locale locale = window.navigator.userLanguage || window.navigator.language || 'en-us' - App.i18n.set( locale ) + App.i18n.set(locale) # rebuild navbar with new navbar items - App.Event.trigger( 'auth' ) - App.Event.trigger( 'auth:logout' ) - App.Event.trigger( 'ui:rerender' ) + App.Event.trigger('auth') + App.Event.trigger('auth:logout') + App.Event.trigger('ui:rerender') return false # clear local store if type isnt 'check' - App.Event.trigger( 'clearStore' ) + App.Event.trigger('clearStore') # update model definition if data.models @@ -103,33 +103,34 @@ class App.Auth # update config for key, value of data.config - App.Config.set( key, value ) + App.Config.set(key, value) # refresh default collections if data.collections - App.Collection.resetCollections( data.collections ) + App.Collection.resetCollections(data.collections) # load assets if data.assets - App.Collection.loadAssets( data.assets ) + App.Collection.loadAssets(data.assets) # store user data sessionUser = App.User.fullLocal(data.session.id) - App.Session.set( sessionUser ) + console.log('set', sessionUser) + App.Session.set(sessionUser) # trigger auth ok with new session data - App.Event.trigger( 'auth', data.session ) + App.Event.trigger('auth', data.session) # init of i18n - preferences = App.Session.get( 'preferences' ) + preferences = App.Session.get('preferences') if preferences && preferences.locale locale = preferences.locale if !locale locale = window.navigator.userLanguage || window.navigator.language || 'en-us' - App.i18n.set( locale ) + App.i18n.set(locale) - App.Event.trigger( 'auth:login', data.session ) - App.Event.trigger( 'ui:rerender' ) + App.Event.trigger('auth:login', data.session) + App.Event.trigger('ui:rerender') @_logout: (data) -> @@ -138,10 +139,10 @@ class App.Auth # empty session App.Session.init() - App.Event.trigger( 'auth' ) - App.Event.trigger( 'auth:logout' ) - App.Event.trigger( 'ui:rerender' ) - App.Event.trigger( 'clearStore' ) + App.Event.trigger('auth') + App.Event.trigger('auth:logout') + App.Event.trigger('ui:rerender') + App.Event.trigger('clearStore') @_loginError: -> App.Log.error 'Auth', '_loginError:error' @@ -150,7 +151,7 @@ class App.Auth App.Session.init() # rebuild navbar - App.Event.trigger( 'auth' ) - App.Event.trigger( 'auth:logout' ) - App.Event.trigger( 'ui:rerender' ) - App.Event.trigger( 'clearStore' ) + App.Event.trigger('auth') + App.Event.trigger('auth:logout') + App.Event.trigger('ui:rerender') + App.Event.trigger('clearStore') diff --git a/app/assets/javascripts/app/lib/app_post/i18n.coffee b/app/assets/javascripts/app/lib/app_post/i18n.coffee index aef9cef14..f0b1ba8c7 100644 --- a/app/assets/javascripts/app/lib/app_post/i18n.coffee +++ b/app/assets/javascripts/app/lib/app_post/i18n.coffee @@ -229,9 +229,15 @@ class _i18nSingleton extends Spine.Module setMap: (source, target, format = 'string') => if format is 'time' - @mapTime[source] = target + if target is '' + delete @mapTime[source] + else + @mapTime[source] = target else - @mapString[source] = target + if target is '' + delete @mapString[source] + else + @mapString[source] = target notTranslatedFeatureEnabled: (locale) -> if locale.substr(0,2) is 'en' diff --git a/app/assets/javascripts/app/lib/app_post/interface_handle.coffee b/app/assets/javascripts/app/lib/app_post/interface_handle.coffee index 0e7ce54fb..0679e76ed 100644 --- a/app/assets/javascripts/app/lib/app_post/interface_handle.coffee +++ b/app/assets/javascripts/app/lib/app_post/interface_handle.coffee @@ -28,13 +28,13 @@ class App.Run extends App.Controller @frontendTimeUpdate() # start navbars - @setupWidget( 'Navigations', 'nav', @el ) + @setupWidget('Navigations', 'nav', @el) # start widgets - @setupWidget( 'Widgets', 'widget', @el ) + @setupWidget('Widgets', 'widget', @el) # bind to fill selected text into - App.ClipBoard.bind( @el ) + App.ClipBoard.bind(@el) App.Event.trigger('app:ready') @@ -99,4 +99,4 @@ class App.Content extends App.ControllerWidgetPermanent Spine.Route.setup() -App.Config.set( 'content', App.Content, 'Widgets' ) +App.Config.set('content', App.Content, 'Widgets') diff --git a/app/assets/javascripts/app/views/translation/english.jst.eco b/app/assets/javascripts/app/views/translation/english.jst.eco deleted file mode 100644 index 28ab07823..000000000 --- a/app/assets/javascripts/app/views/translation/english.jst.eco +++ /dev/null @@ -1 +0,0 @@ -
<%- @T('English is the source language, so we have nothing to translate.') %>
\ No newline at end of file diff --git a/script/build/test_slice_tests.sh b/script/build/test_slice_tests.sh index 09b79c2c4..d19d0c09d 100755 --- a/script/build/test_slice_tests.sh +++ b/script/build/test_slice_tests.sh @@ -28,9 +28,10 @@ elif [ "$LEVEL" == '2' ]; then rm test/browser/prefereces_test.rb rm test/browser/setting_test.rb rm test/browser/signup_password_change_and_reset_test.rb + rm test/browser/switch_to_user_test.rb rm test/browser/taskbar_session_test.rb rm test/browser/taskbar_task_test.rb - rm test/browser/switch_to_user_test.rb + rm test/browser/translation_test.rb elif [ "$LEVEL" == '3' ]; then echo "slicing level 3" @@ -45,9 +46,10 @@ elif [ "$LEVEL" == '3' ]; then rm test/browser/maintenance_message_test.rb rm test/browser/manage_test.rb rm test/browser/signup_password_change_and_reset_test.rb + rm test/browser/switch_to_user_test.rb rm test/browser/taskbar_session_test.rb rm test/browser/taskbar_task_test.rb - rm test/browser/switch_to_user_test.rb + rm test/browser/translation_test.rb else echo "ERROR: Invalid level $LEVEL - 1, 2 or 3 is available" diff --git a/test/browser/translation_test.rb b/test/browser/translation_test.rb new file mode 100644 index 000000000..560fc4f09 --- /dev/null +++ b/test/browser/translation_test.rb @@ -0,0 +1,248 @@ +# encoding: utf-8 +require 'browser_test_helper' + +class TranslationTest < TestCase + def test_preferences + @browser = browser_instance + login( + username: 'master@example.com', + password: 'test', + url: browser_url, + ) + tasks_close_all() + + click(css: 'a[href="#current_user"]') + click(css: 'a[href="#profile"]') + click(css: 'a[href="#profile/language"]') + select( + css: '.language_item select[name="locale"]', + value: 'English (United States)', + ) + click(css: '.content button[type="submit"]') + sleep 2 + watch_for( + css: 'body', + value: 'Language', + ) + + click(css: 'a[href="#manage"]') + click(css: 'a[href="#system/translation"]') + + watch_for( + css: '#content', + value: 'English is the source language, so we have nothing to translate', + ) + + click(css: 'a[href="#current_user"]') + click(css: 'a[href="#profile"]') + click(css: 'a[href="#profile/language"]') + select( + css: '.language_item select[name="locale"]', + value: 'Deutsch', + ) + click(css: '.content button[type="submit"]') + watch_for( + css: 'body', + value: 'Sprache', + ) + + click(css: 'a[href="#manage"]') + click(css: 'a[href="#system/translation"]') + + set( + css: '#content input.js-Item[data-source="Translations"]', + value: 'Übersetzung2', + ) + click(css: '#global-search') + + click(css: 'a[href="#dashboard"]') + click(css: 'a[href="#manage"]') + click(css: 'a[href="#system/translation"]') + sleep 4 + + match( + css: '#content .sidebar', + value: 'Übersetzung2', + ) + match( + css: '#content input.js-Item[data-source="Translations"]', + value: 'Übersetzung2', + ) + + execute( + js: "$('.js-Item[data-source=Translations]').parents('tr').find('.js-Reset:visible').click()", + ) + sleep 5 + + match( + css: '#content .sidebar', + value: 'Übersetzung2', + ) + match_not( + css: '#content input.js-Item[data-source="Translations"]', + value: 'Übersetzung2', + ) + + click(css: 'a[href="#dashboard"]') + + click(css: 'a[href="#manage"]') + click(css: 'a[href="#system/translation"]') + sleep 2 + + match_not( + css: '#content .sidebar', + value: 'Übersetzung2', + ) + match_not( + css: '#content input.js-Item[data-source="Translations"]', + value: 'Übersetzung2', + ) + match_not( + css: '#content .sidebar', + value: 'Übersetzung2', + ) + + @browser.action.key_down(:control) + .key_down(:alt) + .send_keys('t') + .key_up(:alt) + .key_up(:control) + .perform + + watch_for( + css: 'span.translation[title="Overviews"]', + value: 'Übersichten', + ) + set( + css: 'span.translation[title="Overviews"]', + value: 'Übersichten123', + ) + sleep 1 + click(css: '#global-search') + sleep 5 + + @browser.action.key_down(:control) + .key_down(:alt) + .send_keys('t') + .key_up(:alt) + .key_up(:control) + .perform + + sleep 5 + exists_not( + css: 'span.translation[title="Overviews"]', + ) + match( + css: '.js-menu', + value: 'Übersichten123', + ) + + reload() + exists_not( + css: 'span.translation[title="Overviews"]', + ) + match( + css: '.js-menu', + value: 'Übersichten123', + ) + + click(css: 'a[href="#manage"]') + click(css: 'a[href="#system/translation"]') + sleep 4 + + match( + css: '#content input.js-Item[data-source="Overviews"]', + value: 'Übersichten123', + ) + + execute( + js: "$('.js-Item[data-source=Overviews]').parents('tr').find('.js-Reset:visible').click()", + ) + sleep 5 + + click(css: 'a[href="#dashboard"]') + sleep 5 + + match_not( + css: '.js-menu', + value: 'Übersichten123', + ) + match( + css: '.js-menu', + value: 'Übersichten', + ) + + click(css: 'a[href="#current_user"]') + click(css: 'a[href="#profile"]') + click(css: 'a[href="#profile/language"]') + select( + css: '.language_item select[name="locale"]', + value: 'English (United States)', + ) + click(css: '.content button[type="submit"]') + sleep 2 + watch_for( + css: 'body', + value: 'Language', + ) + sleep 5 + + @browser.action.key_down(:control) + .key_down(:alt) + .send_keys('t') + .key_up(:alt) + .key_up(:control) + .perform + + watch_for( + css: 'span.translation[title="Overviews"]', + value: 'Overviews', + ) + set( + css: 'span.translation[title="Overviews"]', + value: 'Overviews123', + ) + sleep 1 + click(css: '#global-search') + sleep 5 + + @browser.action.key_down(:control) + .key_down(:alt) + .send_keys('t') + .key_up(:alt) + .key_up(:control) + .perform + + sleep 5 + exists_not( + css: 'span.translation[title="Overviews"]', + ) + match( + css: '.js-menu', + value: 'Overviews123', + ) + + click(css: 'a[href="#manage"]') + click(css: 'a[href="#system/translation"]') + sleep 4 + + match( + css: '#content input.js-Item[data-source="Overviews"]', + value: 'Overviews123', + ) + match_not( + css: '#content', + value: 'English is the source language, so we have nothing to translate', + ) + + execute( + js: "$('.js-Item[data-source=Overviews]').parents('tr').find('.js-Reset:visible').click()", + ) + + watch_for( + css: '#content', + value: 'English is the source language, so we have nothing to translate', + ) + + end +end diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index 0cad5b8e2..d4da873f5 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -347,8 +347,7 @@ class TestCase < Test::Unit::TestCase instance = params[:browser] || @browser if params[:js] - instance.execute_script(params[:js]) - return + return instance.execute_script(params[:js]) end fail "Invalid execute params #{params.inspect}" end