Fixes #3846 - Simple quote characters (') not properly displayed.

This commit is contained in:
Dominik Klein 2021-11-23 20:02:33 +01:00
parent 10be8dabd3
commit 8b16f483d6
3 changed files with 32 additions and 6 deletions

View file

@ -155,4 +155,4 @@ class App.UiElement.basedate
clear: 'clear' clear: 'clear'
} }
App.i18n.translateDeep(data) App.i18n.translateDeepPlain(data)

View file

@ -8,7 +8,12 @@ class App.i18n
@translateDeep: (input, args...) -> @translateDeep: (input, args...) ->
if _instance == undefined if _instance == undefined
_instance ?= new _i18nSingleton() _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...) -> @translateContent: (string, args...) ->
if _instance == undefined if _instance == undefined
@ -230,15 +235,18 @@ class _i18nSingleton extends Spine.Module
return string if !string return string if !string
@translate(string, args, true) @translate(string, args, true)
translateDeep: (input, args) => translateDeep: (input, args, plain) =>
if _.isArray(input) if _.isArray(input)
_.map input, (item) => _.map input, (item) =>
@translateDeep(item, args) @translateDeep(item, args, plain)
else if _.isObject(input) else if _.isObject(input)
_.reduce _.keys(input), (memo, item) => _.reduce _.keys(input), (memo, item) =>
memo[item] = @translateDeep(input[item]) memo[item] = @translateDeep(input[item], args, plain)
memo memo
, {} , {}
else
if plain
@translatePlain(input, args)
else else
@translateInline(input, args) @translateInline(input, args)

View file

@ -70,6 +70,24 @@ test('i18n .detectBrowserLocale', function() {
translated = App.i18n.translateInline('yes') translated = App.i18n.translateInline('yes')
equal(translated, 'ja', 'de-de - yes / ja translated correctly') equal(translated, 'ja', 'de-de - yes / ja translated correctly')
translated = App.i18n.translateDeep({
days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
today: 'today',
})
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',
})
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); translated = App.i18n.translateContent('%s ago', 123);
equal(translated, 'vor 123', 'de-de - %s') equal(translated, 'vor 123', 'de-de - %s')