Skip to main content

Create your Custom Component with i18n-keyless props

In React Native, it is much recommended already to create a component MyText or whatever you call it, otherwise managing font-family is really tough. Therefore it will be much straight forward to integrate i18n-keyless.

For web React projects it is less common, but for using i18n-keyless it is recommended too.

Here are our current implementation in our production projetcs.

/src/components/MyText.tsx
import { I18nKeylessText, type I18nKeylessTextProps } from "i18n-keyless-react";

interface MyTextProps {
skipTranslation?: boolean;
i18nProps?: I18nKeylessTextProps;
children: I18nKeylessTextProps["children"];
debug?: boolean;
}

// you could take the opportunity to add `className, `style`, or `font-family`, whatever

export default function MyText({
children,
skipTranslation = false,
debug = false,
}: MyTextProps) {

if (skipTranslation) {
if (debug) {
console.log("skipTranslation", children);
}
return children;
}

if (debug) {
console.log("children translated", children);
}

return (
<I18nKeylessText
context={i18nProps?.context}
replace={i18nProps?.replace}
forceTemporary={i18nProps?.forceTemporary}
debug={debug || i18nProps?.debug}
>
{children}
</I18nKeylessText>
);
}