Open gabric098 opened 2 years ago
same issue here , and I found it can get two in pages/index , but can only get one in component/Header/index try to find what's wrong too ;( any help/suggestions welcome
I think it's because of my gatsby-browser.tsx. so I can not access the whole languages. but, still I don't know how to fix this yet, keep working on it ;(
I think I found some solution, maybe could work. so, I found it in someone else blog structure. It's gatsby-browser file :
I change mine to :
export const wrapPageElement: GatsbyBrowser["wrapPageElement"] = ({
props,
element,
}) => {
return React.cloneElement(
element, // I18nextProvider
props,
element.props.children &&
React.cloneElement(
element.props.children, // I18nextContext.Provider
element.props.children?.props,
React.createElement(
Container,
props,
element.props.children?.props.children
)
)
);
};
and this work foe me. It's a typescript version btw. hope it works for you too
Hey @Dennnnny It does work indeed! would you mind sharing the source where you found an example of this solution? I can't quite figure out why it's working.
Thank you!
@gabric098 here's what I found : https://andremonteiro.pt/gatsby-i18next-wrap-page-element/
Thank you @Dennnnny, really appreciated
I'm running
gatsby 4.12.1
withreact 18.2.0
using latest version ofgatsby-plugin-react-i18next
. I followed the examples included in the plugin. When I try to obtain the list of available languages using the following code:I keep getting only
['en']
in thelanguages
array even if there's no en language defined in my setup.Here's how my
gatsby-config.js
looks like:I've created the following files:
locales/de/translation.json
locales/es/translation.json
All seems to be working fine, If I access
http://localhost:8000/
I get the German translations, If I accesshttp://localhost:8000/es
I get the Spanish. However, when I try to list the available languages by using the following code:no matter what,
languages
always contains a single elementen
.Does anyone have any idea about what I'm doing wrong?