From 8b0e6c8cee83e9e22b63ae3a8f0d12f0d6d636a9 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 26 Jul 2015 21:28:49 +0200 Subject: [PATCH] Fixed multiple %s replacements. --- app/assets/javascripts/app/index.js.coffee | 6 ++--- .../app/lib/app_post/i18n.js.coffee | 14 +++++------ public/assets/tests/core.js | 24 +++++++++++++++++++ 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/app/index.js.coffee b/app/assets/javascripts/app/index.js.coffee index ae5bd2aa7..36fcebebf 100644 --- a/app/assets/javascripts/app/index.js.coffee +++ b/app/assets/javascripts/app/index.js.coffee @@ -171,11 +171,11 @@ class App extends Spine.Controller # define translation helper params.T = ( item, args... ) -> - App.i18n.translateContent( item, args ) + App.i18n.translateContent( item, args... ) # define translation inline helper - params.Ti = ( item, args... ) -> - App.i18n.translateInline( item, args ) + params.Ti = ( item, args... ) -> + App.i18n.translateInline( item, args... ) # define linkify helper params.L = ( item ) -> 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 5e766da7e..d46a133cf 100644 --- a/app/assets/javascripts/app/lib/app_post/i18n.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/i18n.js.coffee @@ -214,11 +214,11 @@ class _i18nSingleton extends Spine.Module App.Event.trigger('i18n:language:change') ) - translateInline: ( string, args... ) => - App.Utils.htmlEscape( @translate( string, args... ) ) + translateInline: ( string, args ) => + App.Utils.htmlEscape( @translate( string, args ) ) - translateContent: ( string, args... ) => - translated = App.Utils.htmlEscape( @translate( string, args... ) ) + translateContent: ( string, args ) => + translated = App.Utils.htmlEscape( @translate( string, args ) ) # replace = '' + translated + '' if App.Config.get( 'translation_inline' ) replace = '' + translated + '' @@ -228,10 +228,10 @@ class _i18nSingleton extends Spine.Module else translated - translatePlain: ( string, args... ) => - @translate( string, args... ) + translatePlain: ( string, args ) => + @translate( string, args ) - translate: ( string, args... ) => + translate: ( string, args ) => # type convertation if typeof string isnt 'string' diff --git a/public/assets/tests/core.js b/public/assets/tests/core.js index 4378d5a07..eae8f4c86 100644 --- a/public/assets/tests/core.js +++ b/public/assets/tests/core.js @@ -262,6 +262,18 @@ test( "i18n", function() { var translated = App.i18n.translateContent('yes'); equal( translated, 'ja', 'de-de - yes / ja translated correctly' ); + translated = App.i18n.translatePlain('yes'); + equal( translated, 'ja', 'de-de - yes / ja translated correctly' ); + + translated = App.i18n.translateInline('yes'); + equal( translated, 'ja', 'de-de - yes / ja translated correctly' ); + + translated = App.i18n.translateContent('%s ago', 123); + equal( translated, 'vor 123', 'de-de - %s' ); + + translated = App.i18n.translateContent('%s %s test', 123, 'xxx'); + equal( translated, '123 xxx test', 'de-de - %s %s' ); + translated = App.i18n.translateContent('//*äöüß'); equal( translated, '<test&now>//*äöüß', 'de - //*äöüß' ); @@ -275,6 +287,18 @@ test( "i18n", function() { translated = App.i18n.translateContent('yes'); equal( translated, 'yes', 'en-us - yes translated correctly' ); + translated = App.i18n.translatePlain('yes'); + equal( translated, 'yes', 'en-us - yes translated correctly' ); + + translated = App.i18n.translateInline('yes'); + equal( translated, 'yes', 'en-us - yes translated correctly' ); + + translated = App.i18n.translateContent('%s ago', 123); + equal( translated, '123 ago', 'en-us - %s' ); + + translated = App.i18n.translateContent('%s %s test', 123, 'xxx'); + equal( translated, '123 xxx test', 'en-us - %s %s' ); + translated = App.i18n.translateContent(''); equal( translated, '<test&now>', 'en-us - ' );