I'm working in a component to show a simple message.
The issue I have is because that message should be localized using i18next in the parent's namespace:
Here is the code I've tried:
interface StatusErrorInterface {
namespace: string;
keyName: string;
defaultValue: string;
}
const StatusError = ({
namespace,
keyName,
defaultValue,
}: StatusErrorInterface): ReactElement => {
const { t } = useTranslation(namespace);
return (
<View>
<Text>
{t(keyName, {
defaultValue: `${defaultValue}`,
})}
</Text>
</View>
);
};
And implementation looks like this:
<StatusError
namespace="namespace-name"
keyName="key-name"
defaultValue="default value" />
Is there any way to avoid passing namespace? My goal is to add this new key to the parent's namespace, without need to write it over and over.
question from:
https://stackoverflow.com/questions/65851577/using-component-with-i18next-based-on-parent-namespace 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…