From e4a14268d6d984df52938fdf20dfa2444453f0f7 Mon Sep 17 00:00:00 2001 From: Dominik Klein Date: Mon, 22 Nov 2021 13:36:57 +0100 Subject: [PATCH] Fixes #3846 - Simple quote characters (`'`) not properly displayed. --- .../controllers/_ui_element/basedate.coffee | 2 +- .../javascripts/app/lib/app_post/i18n.coffee | 18 +++++++++++++----- public/assets/tests/qunit/i18n.js | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_ui_element/basedate.coffee b/app/assets/javascripts/app/controllers/_ui_element/basedate.coffee index d5bb87848..900e5cbec 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/basedate.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/basedate.coffee @@ -155,4 +155,4 @@ class App.UiElement.basedate clear: __('clear') } - App.i18n.translateDeep(data) + App.i18n.translateDeepPlain(data) diff --git a/app/assets/javascripts/app/lib/app_post/i18n.coffee b/app/assets/javascripts/app/lib/app_post/i18n.coffee index a67cad93c..81234c313 100644 --- a/app/assets/javascripts/app/lib/app_post/i18n.coffee +++ b/app/assets/javascripts/app/lib/app_post/i18n.coffee @@ -8,7 +8,12 @@ class App.i18n @translateDeep: (input, args...) -> if _instance == undefined _instance ?= new _i18nSingleton() - _instance.translateDeep(input, args) + _instance.translateDeep(input, args, false) + + @translateDeepPlain: (input, args...) -> + if _instance == undefined + _instance ?= new _i18nSingleton() + _instance.translateDeep(input, args, true) @translateContent: (string, args...) -> if _instance == undefined @@ -205,17 +210,20 @@ class _i18nSingleton extends Spine.Module return string if !string @translate(string, args, true) - translateDeep: (input, args) => + translateDeep: (input, args, plain) => if _.isArray(input) _.map input, (item) => - @translateDeep(item, args) + @translateDeep(item, args, plain) else if _.isObject(input) _.reduce _.keys(input), (memo, item) => - memo[item] = @translateDeep(input[item]) + memo[item] = @translateDeep(input[item], args, plain) memo , {} else - @translateInline(input, args) + if plain + @translatePlain(input, args) + else + @translateInline(input, args) translateContent: (string, args) => diff --git a/public/assets/tests/qunit/i18n.js b/public/assets/tests/qunit/i18n.js index bec133e44..c651aedac 100644 --- a/public/assets/tests/qunit/i18n.js +++ b/public/assets/tests/qunit/i18n.js @@ -71,6 +71,24 @@ QUnit.test('i18n', assert => { translated = App.i18n.translateInline('yes') assert.equal(translated, 'ja', 'de-de - yes / ja translated correctly') + translated = App.i18n.translateDeep({ + days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], + today: 'today', + }) + assert.deepEqual(translated, { + days: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'], + today: 'Heute', + }, 'de-de - deep object/array translated correctly') + + translated = App.i18n.translateDeepPlain({ + days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], + today: 'today', + }) + assert.deepEqual(translated, { + days: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'], + today: 'Heute', + }, 'de-de - deep object/array translated correctly') + translated = App.i18n.translateContent('%s ago', 123); assert.equal(translated, 'vor 123', 'de-de - %s')