Skip to content

Commit

Permalink
Skipped custom html tags
Browse files Browse the repository at this point in the history
  • Loading branch information
nkhristinin committed Jul 25, 2018
1 parent 1dc13d3 commit 7532331
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Trans.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions test/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ i18n
interpolateKey2: '<strong>add</strong> {{insert}} {{up, uppercase}}',
transTest1: "Go <1>there</1>.",
transTest1_noParent: "<0>Go <1>there</1>.</0>",
transTest1_customHtml: "Go <br/><1>there</1>.",
transTest2: "Hello <1><0>{{name}}</0></1>, you have <3>{{count}}</3> message. Open <5>hear</5>.",
transTest2_plural: "Hello <1><0>{{name}}</0></1>, you have <3>{{count}}</3> messages. Open <5>here</5>.",
testTransKey1: "<0>{{numOfItems}}</0> item matched.",
Expand Down
23 changes: 23 additions & 0 deletions test/trans.render.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,29 @@ describe('trans simple using ns prop', () => {
});
});

describe('trans simple with custom html tag', () => {
const TestElement = ({ t, parent }) => {
return (
<Trans i18nKey="transTest1_customHtml" parent={parent}>
Open <Link to="/msgs">here</Link>.
</Trans>
);
}

it('should skip custom html tags', () => {
const HocElement = translate(['translation'], {})(TestElement);

const wrapper = mount(<HocElement />, { context });
// console.log(wrapper.debug());
expect(wrapper.contains(
<div>
Go <Link to="/msgs">there</Link>.
</div>
)).toBe(true);
});

})

describe('trans testTransKey1 singular', () => {
const TestElement = ({ t }) => {
const numOfItems = 1;
Expand Down

0 comments on commit 7532331

Please sign in to comment.