Skip to content

wrapPageElement error: You will need to pass in an i18next instance by using initReactI18next #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
leduchung opened this issue Feb 12, 2022 · 5 comments

Comments

@leduchung
Copy link

The translation works well, but when I put the Layout component (including NavBar and Footer) into the wrapPageElement in gatsby-browser.js, no language detected and following message is thrown in the console: You will need to pass in an i18next instance by using initReactI18next.

Do you have any hint to implement custom wrapPageElement with the plugin?

@andremonteiro95
Copy link

I managed to make it work with wrapPageElement, you can find a detailed post about the solution I came up with in my blog: https://andremonteiro.pt/gatsby-i18next-wrap-page-element/

@leduchung
Copy link
Author

Great thanks! Your solution works well and nice explanation. I had a small difference is that my Layout component requires props to get data from graphQL, so I put in the props instead of undefined.

@leduchung
Copy link
Author

Now I faced another case. The message appears at the first time opening the page (e.g. via a new Incognito windows in Chrome) when there is no language selected. Hence, the plugin fallback to English language which is /en instead of default language. Inspecting the console, there is no i18n in the props.

If I select one language, everything start to work fine.

@leduchung leduchung reopened this Feb 21, 2022
@andremonteiro95
Copy link

andremonteiro95 commented Feb 21, 2022

@leduchung glad to hear that! do you have an implementation of wrapPageElement on both gatsby-ssr.js and gatsby-browser.js files?

@leduchung
Copy link
Author

@andremonteiro95 yes I did both files. After a while, I found that it was another issue #89, so everything work fine for my site now. Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants