Skip to content

Commit

Permalink
render all children regardless of type when using i18nIsDynamicList prop
Browse files Browse the repository at this point in the history
  • Loading branch information
nicegamer7 committed Aug 10, 2023
1 parent b5efaa9 commit 0de7198
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/TransWithoutContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, s
function renderInner(child, node, rootReactNode) {
const childs = getChildren(child);
const mappedChildren = mapAST(childs, node.children, rootReactNode);
return hasValidReactChildren(childs) && mappedChildren.length === 0 ? childs : mappedChildren;
// `mappedChildren` will always be empty if using the `i18nIsDynamicList` prop,
// but the children might not necessarily be react components
return (hasValidReactChildren(childs) && mappedChildren.length === 0) ||
child.props?.i18nIsDynamicList
? childs
: mappedChildren;
}

function pushTranslatedJSX(child, inner, mem, i, isVoid) {
Expand Down
21 changes: 20 additions & 1 deletion test/trans.render.dynamic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('Trans should render nested components', () => {
`);
});

it('should render dynamic content correctly', () => {
it('should render dynamic Elements correctly', () => {
const dynamicContent = <div>testing</div>;

function TestComponent() {
Expand All @@ -90,4 +90,23 @@ describe('Trans should render nested components', () => {
</div>
`);
});

it('should render dynamic strings correctly', () => {
const dynamicContent = 'testing';

function TestComponent() {
return (
<Trans>
My dynamic content: <React.Fragment i18nIsDynamicList>{dynamicContent}</React.Fragment>
</Trans>
);
}
const { container } = render(<TestComponent />);
expect(container.firstChild).toMatchInlineSnapshot(`
<div>
My dynamic content:
testing
</div>
`);
});
});

0 comments on commit 0de7198

Please sign in to comment.