-
GoalI'm trying to change the location of the locales using the ErrorWhen I start the dev server and try to access any of the pages, I end up with the following error. CodeYou can see my code at https://github.com/crs1138/next-translate/tree/load-locale-from And the snippet of the i18n.json including the module.exports = {
locales: ['en', 'ca', 'es', 'cs'],
defaultLocale: 'en',
pages: {
'*': ['common'],
'/[lang]': ['home'],
'/[lang]/second-page': ['home'],
'/[lang]/[slug]': ['home'],
},
loadLocaleFrom: (locale, namespace) => {
const i18nLocale = `./honza/${locale}/${namespace}.json`
console.log('i18n.js > loadLocaleFrom() :::', { i18nLocale })
return import(i18nLocale)
.then((m) => m.default)
.catch((e) => console.error(e))
},
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
After running some more test, I discovered:
Somehow this works fine (I can't comprehend what's going on here, why is this different???): module.exports = {
locales: ['en', 'ca', 'es', 'cs'],
defaultLocale: 'en',
pages: {
'*': ['common'],
'/[lang]': ['home'],
'/[lang]/second-page': ['home'],
'/[lang]/[slug]': ['home'],
},
loadLocaleFrom: (locale, namespace) =>
import(`./honza/${locale}/${namespace}.json`)
.then((m) => m.default)
.catch((e) => console.error(e)),
// loadLocaleFrom: (locale, namespace) => {
// const i18nLocale = `./honza/${locale}/${namespace}.json`
// console.log('i18n.js > loadLocaleFrom() :::', { i18nLocale })
// return import(i18nLocale)
// .then((m) => m.default)
// .catch((e) => console.error(e))
// },
} |
Beta Was this translation helpful? Give feedback.
The culprit seems to be the parameter of the
import()
function, as the following code works.