I'm using a "custom" implementation of i18n with react-i18next, i18next-xhr-backend, etc because I needed a custom language detector. Here are the problems I have:
There is a <Newsletter /> functional component included in index.js and I'm using const { t } = useTranslation() to get translations. Now that works perfectly in development, on production it doesn't work on hard refresh or first load, only on page change. Doesn't work meaning it loads the fallback language. Same thing happens with <Card /> class component included in index.js and in it I'm using export default withTranslation()(Card) and then const { t } = this.props.
On index.js I'm using withTranslation just like in Card component and that's working perfectly, then I have contact.js setup in same way but the translations will use fallback language until I add any kind of graphql query on that page, then it will load the proper language.
What am I doing wrong? Do I need some kind of a i18n provider in my Layout? Do I need something in gatsby-ssr? Do I need to load locales via graphql somehow?
Relevant information
Layout.js:
import React, { Component } from "react"
import "components/i18n"
class Layout extends Component {
render() {
const { location, children } = this.props
return <>{children}</>
}
}
export default Layout
Summary
I'm using a "custom" implementation of i18n with
react-i18next
,i18next-xhr-backend
, etc because I needed a custom language detector. Here are the problems I have:There is a
<Newsletter />
functional component included inindex.js
and I'm usingconst { t } = useTranslation()
to get translations. Now that works perfectly in development, on production it doesn't work on hard refresh or first load, only on page change. Doesn't work meaning it loads the fallback language. Same thing happens with<Card />
class component included inindex.js
and in it I'm usingexport default withTranslation()(Card)
and thenconst { t } = this.props
.On
index.js
I'm using withTranslation just like in Card component and that's working perfectly, then I havecontact.js
setup in same way but the translations will use fallback language until I add any kind of graphql query on that page, then it will load the proper language.What am I doing wrong? Do I need some kind of a i18n provider in my Layout? Do I need something in gatsby-ssr? Do I need to load locales via graphql somehow?
Relevant information
Layout.js
:i18n.js
:Environment
File contents
gatsby-config.js
:package.json
:gatsby-node.js
:gatsby-browser.js
: N/Agatsby-ssr.js
: N/A