Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
43 lines
1.2 KiB
Plaintext
43 lines
1.2 KiB
Plaintext
import { jsx as _jsx } from "react/jsx-runtime";
|
|
import * as React from 'react';
|
|
const RecursiveTranslation = ({
|
|
elements,
|
|
translationString
|
|
}) => {
|
|
const regex = /(<[^>]+>.*?<\/[^>]+>)/g;
|
|
const sections = translationString.split(regex);
|
|
return /*#__PURE__*/_jsx("span", {
|
|
children: sections.map((section, index) => {
|
|
if (elements && section.startsWith('<') && section.endsWith('>')) {
|
|
const elementKey = section[1];
|
|
const Element = elements[elementKey];
|
|
if (Element) {
|
|
const regex = new RegExp(`<${elementKey}>(.*?)<\/${elementKey}>`, 'g');
|
|
const children = section.replace(regex, (_, group) => group);
|
|
return /*#__PURE__*/_jsx(Element, {
|
|
children: /*#__PURE__*/_jsx(RecursiveTranslation, {
|
|
translationString: children
|
|
})
|
|
}, index);
|
|
}
|
|
}
|
|
return section;
|
|
})
|
|
});
|
|
};
|
|
export const Translation = ({
|
|
elements,
|
|
i18nKey,
|
|
t,
|
|
variables
|
|
}) => {
|
|
const stringWithVariables = t(i18nKey, variables || {});
|
|
if (!elements) {
|
|
return stringWithVariables;
|
|
}
|
|
return /*#__PURE__*/_jsx(RecursiveTranslation, {
|
|
elements: elements,
|
|
translationString: stringWithVariables
|
|
});
|
|
};
|
|
//# sourceMappingURL=index.js.map |