diff --git a/application/source/i18n/providers/embed.mjs b/application/source/i18n/providers/embed.mjs index 0f2e5a1c075305ee1cb0397fed2d777d36ef2886..c82e91e69419e25ef3cd7ecc236859fb0362b06b 100644 --- a/application/source/i18n/providers/embed.mjs +++ b/application/source/i18n/providers/embed.mjs @@ -109,7 +109,7 @@ class Embed extends Provider { let translations = null; try { - translations = JSON.parse(this.translateElement.innerHTML); + translations = JSON.parse(this.translateElement.innerHTML.trim()); } catch (e) { reject(e); return; @@ -150,8 +150,6 @@ class Embed extends Provider { const promises = []; - let result - list.forEach((translationElement) => { const p = new Embed(translationElement); promises.push(p.assignToElement(undefined, element)); diff --git a/development/test/cases/data/pipe.mjs b/development/test/cases/data/pipe.mjs index 3f4f9fbaca8c63a888426b92f27a2a6eb9a951f8..5539e7dc00ffe65e93be0bc5f99b41414b902e82 100644 --- a/development/test/cases/data/pipe.mjs +++ b/development/test/cases/data/pipe.mjs @@ -3,6 +3,7 @@ import {expect} from "chai" import {Pipe} from "../../../../application/source/data/pipe.mjs"; import {initJSDOM} from "../../util/jsdom.mjs"; +import {Embed} from "../../../../application/source/i18n/providers/embed.mjs"; describe('Pipe', function () { @@ -10,7 +11,7 @@ describe('Pipe', function () { before(function (done) { let promises = [] - if(!globalThis['crypto']) { + if (!globalThis['crypto']) { promises.push(import("@peculiar/webcrypto").then(m => { globalThis['crypto'] = new m.Crypto(); return true; @@ -21,12 +22,12 @@ describe('Pipe', function () { done() }); - }); - + }); + describe('run different pipes', function () { [ - ['path:b | if:x:\\ ', {a:true}, ' '], // '\\ '.length ↦ 2 - ['path:a | if:x:\\ ', {a:true}, 'x'], + ['path:b | if:x:\\ ', {a: true}, ' '], // '\\ '.length ↦ 2 + ['path:a | if:x:\\ ', {a: true}, 'x'], ['nop', 'abcdefghijklmnop', 'abcdefghijklmnop'], ].forEach(function (data) { @@ -83,4 +84,63 @@ describe('Pipe', function () { }); + + describe('new Pipe and locale', function () { + + + let html1 = ` +<div id="mock-translations"></div> +<script type="application/json" data-monster-role="translations"> + { + "51": "xyz", + "52": "abc", + "53": "def" + } +</script> +`; + + beforeEach((done) => { + let mocks = document.getElementById('mocks'); + mocks.innerHTML = html1; + let elem = document.getElementById('mock-translations'); + Embed.assignTranslationsToElement(elem).then((o) => { + done() + }).catch((e) => { + done(e) + }) + + + }) + + afterEach(() => { + let mocks = document.getElementById('mocks'); + mocks.innerHTML = ""; + }) + + before(function (done) { + initJSDOM().then(() => { + done() + }); + }); + + [ + ['path:status | tostring | i18n', {status: 51}, "xyz"] + + + ].forEach(function (data) { + + let pipe = data.shift() + let obj = data.shift() + let expected = data.shift() + + it('should transform(' + pipe + ').run(' + JSON.stringify(obj) + ') return ' + JSON.stringify(expected), function () { + let t = new Pipe(pipe); + expect(t.run(obj)).to.be.equal(expected); + }); + }) + + + }) + + });