It's been some days I'm trying to fix this problem but without success... I'm trying tu use next-i18next to get some translations keys coming from a CMS. We are in SSR, that why I use getServersSideProps. But got the ._nextI18Next.userConfig.use[0]returned from
getServerSideProps` in "/" error. Do you guys got some ideas ? Am I on a bad way ? Thanks a lot for your time and your help.
Here is my next-i18next.config.js :
/* eslint-disable @typescript-eslint/no-var-requires */
const i18nextHttpBackend = require('i18next-http-backend')
const i18nextBrowserLanguageDetector = require('i18next-browser-languagedetector')
const axios = require('axios')
module.exports = {
i18n: {
defaultLocale: 'default',
locales: ['default', 'gb', 'fr']
},
use: [i18nextHttpBackend, i18nextBrowserLanguageDetector],
debug: true,
fallbackLng: 'fr',
interpolation: {
format: (value, format, lng) => {
if (value instanceof Date) {
return DateTime.fromJSDate(value).setLocale(lng).toLocaleString(DateTime[format])
}
return value
}
},
backend: {
loadPath: lng => {
axios.get(`https://my_api_url/${lng}/formatted-transkeys`).then(res => {
return JSON.stringify(res.data)
})
}
},
serializeConfig: false
}
My next.config.js :
/* eslint-disable @typescript-eslint/no-var-requires */
const { i18n } = require('./next-i18next.config')
const nextConfig = {
distDir: 'dist',
reactStrictMode: false,
i18n,
trailingSlash: true,
images: {
domains: ['d1m7xnn75ypr6t.cloudfront.net']
}
}
module.exports = nextConfig
And my index.tsx :
interface i18nProps {
locale: string
}
export const getServerSideProps = async (props: i18nProps) => {
const result = await getHomePageData(props.locale)
const data = result.data
return {
props: {
data: data,
...(await serverSideTranslations(props.locale, ['search']))
}
}
}
export default Homepage
Trying to be as clear as I can, ask me everything you need.
Thanks,
R.