Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
457 views
in Technique[技术] by (71.8m points)

react native - Using component with i18next based on parent namespace

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...