question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react.i18next.com Is working fine inside my main Project but not in my npm package which i used inside my main Project

See original GitHub issue

Question about react-i18next

Questions should be posted on StackOverflow I have two project

  • One is main project
  • Second one is my react npm package(repository) which i used inside my main project’s package.json file as below, "dependencies": { "package-name": "git+https://oauth2:<Access-Token>@gitlab.com/<Project-name>/react-menu.git" }

So if i followed all the steps given over here : https://react.i18next.com/latest/using-with-hooks Then it is working fine in main project using both way using Hook and using HOC

But when i am trying to add same code inside my another repository as i mentioned above then it is throwing error like below https://reactjs.org/docs/error-decoder.html/?invariant=321

So i dont know what was wrong.

Can you guys help me with this.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rawbeanscommented, Apr 29, 2020

When I try:

import i18n from 'i18next';
// then later:
i18n.t("text to translate');

From within my component library, that i18n instance is different from the one in my main app that is importing my component library. The result is empty strings for all translations in my component library.

Where and how did you initialize your i18next instance? How are your two projects set up?

Update: I got it to work by doing the following:

import { useTranslation } from 'react-i18next';
// then later:
const { t } = useTranslation();
t("text to translate');

And in my component library package.json, adding the following to peerDependencies:

"peerDependencies": {
    "react-i18next": "^11.4.0",
},

That way, the main projects i18n instance was used instead of bundling a separate version of all i18next packages and creating a second instance.

0reactions
ParthCodeDevcommented, May 14, 2020

When I try:

import i18n from 'i18next';
// then later:
i18n.t("text to translate');

From within my component library, that i18n instance is different from the one in my main app that is importing my component library. The result is empty strings for all translations in my component library.

Where and how did you initialize your i18next instance? How are your two projects set up?

Update: I got it to work by doing the following:

import { useTranslation } from 'react-i18next';
// then later:
const { t } = useTranslation();
t("text to translate');

And in my component library package.json, adding the following to peerDependencies:

"peerDependencies": {
    "react-i18next": "^11.4.0",
},

That way, the main projects i18n instance was used instead of bundling a separate version of all i18next packages and creating a second instance.

I have two project one is main project second one is react menu repositry from which i get menu

Inside my main project i handle everything regarding translation and whatever translation text i need inside my second project i am passing it as props so i can access them inside my second project

Read more comments on GitHub >

github_iconTop Results From Across the Web

React i18next fails to load translation after in build
I'm using the react build folder inside Django project. It works fine on localhost:3000 only which is crazy but once i try to...
Read more >
Getting started - i18next documentation
Optimized to load i18next in webpack, rollup, ... or node.js. The correct entry points are already configured in the package.json so there should...
Read more >
TypeScript - react-i18next documentation
If your project is relying on TypeScript 4.1+, and you want to enhance IDE Experience and prevent ... import all namespaces (for the...
Read more >
Getting started - react-i18next documentation
react -i18next can be added to your project using npm: # npm ... The correct entry points are already configured in the package.json....
Read more >
Step by step guide - react-i18next documentation
If you need to access the t function or the i18next instance from outside of a React component you can simply import your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found