From 7532331c384f059ef2c4416b96e84e3b9e428ea0 Mon Sep 17 00:00:00 2001 From: nkhristinin Date: Wed, 25 Jul 2018 15:21:26 +0300 Subject: [PATCH] Skipped custom html tags --- src/Trans.js | 7 +++++-- test/i18n.js | 1 + test/trans.render.spec.js | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Trans.js b/src/Trans.js index 956304627..97bfcadd4 100644 --- a/src/Trans.js +++ b/src/Trans.js @@ -75,8 +75,11 @@ function renderNodes(children, targetString, i18n) { inner )); } else if (typeof child === 'object' && !isElement) { - const interpolated = i18n.services.interpolator.interpolate(node.children[0].content, child, i18n.language); - mem.push(interpolated); + const content = node.children[0] ? node.children[0].content : null + if (content) { + const interpolated = i18n.services.interpolator.interpolate(node.children[0].content, child, i18n.language); + mem.push(interpolated); + } } else { mem.push(child); } diff --git a/test/i18n.js b/test/i18n.js index a61755e20..a11b5e611 100644 --- a/test/i18n.js +++ b/test/i18n.js @@ -14,6 +14,7 @@ i18n interpolateKey2: 'add {{insert}} {{up, uppercase}}', transTest1: "Go <1>there.", transTest1_noParent: "<0>Go <1>there.", + transTest1_customHtml: "Go
<1>there.", transTest2: "Hello <1><0>{{name}}, you have <3>{{count}} message. Open <5>hear.", transTest2_plural: "Hello <1><0>{{name}}, you have <3>{{count}} messages. Open <5>here.", testTransKey1: "<0>{{numOfItems}} item matched.", diff --git a/test/trans.render.spec.js b/test/trans.render.spec.js index d2b91b705..d553026de 100644 --- a/test/trans.render.spec.js +++ b/test/trans.render.spec.js @@ -105,6 +105,29 @@ describe('trans simple using ns prop', () => { }); }); +describe('trans simple with custom html tag', () => { + const TestElement = ({ t, parent }) => { + return ( + + Open here. + + ); + } + + it('should skip custom html tags', () => { + const HocElement = translate(['translation'], {})(TestElement); + + const wrapper = mount(, { context }); + // console.log(wrapper.debug()); + expect(wrapper.contains( +
+ Go there. +
+ )).toBe(true); + }); + +}) + describe('trans testTransKey1 singular', () => { const TestElement = ({ t }) => { const numOfItems = 1;