diff --git a/src/TransWithoutContext.js b/src/TransWithoutContext.js index 37b51084c..9260f315d 100644 --- a/src/TransWithoutContext.js +++ b/src/TransWithoutContext.js @@ -47,19 +47,22 @@ export const nodesToString = (children, i18nOptions) => { // expected e.g. lorem stringNode += `${child}`; } else if (isValidElement(child)) { - const childPropsCount = Object.keys(child.props).length; - const shouldKeepChild = keepArray.indexOf(child.type) > -1; - const childChildren = child.props.children; + const { props, type } = child; + const childPropsCount = Object.keys(props).length; + const shouldKeepChild = keepArray.indexOf(type) > -1; + const childChildren = props.children; - if (!childChildren && shouldKeepChild && childPropsCount === 0) { + if (!childChildren && shouldKeepChild && !childPropsCount) { // actual e.g. lorem
ipsum // expected e.g. lorem
ipsum - stringNode += `<${child.type}/>`; - } else if (!childChildren && (!shouldKeepChild || childPropsCount !== 0)) { + stringNode += `<${type}/>`; + } else if ( + (!childChildren && (!shouldKeepChild || childPropsCount)) || + props.i18nIsDynamicList + ) { // actual e.g. lorem
ipsum // expected e.g. lorem <0> ipsum - stringNode += `<${childIndex}>`; - } else if (child.props.i18nIsDynamicList) { + // or // we got a dynamic list like // e.g. // expected e.g. "<0>", not e.g. "<0><0>a<1>b" @@ -67,7 +70,7 @@ export const nodesToString = (children, i18nOptions) => { } else if (shouldKeepChild && childPropsCount === 1 && isString(childChildren)) { // actual e.g. dolor bold amet // expected e.g. dolor bold amet - stringNode += `<${child.type}>${childChildren}`; + stringNode += `<${type}>${childChildren}`; } else { // regular case mapping the inner children const content = nodesToString(childChildren, i18nOptions);