Dennis - Platowner
Dennis - Platowner
NNuxt
Created by Dennis - Platowner on 2/20/2025 in #❓・help
Nuxtjs/I18n not initialising properly
We used the nuxtjs/i18n v8.0.0-rc3, and now started upgrading to v9.2.1. We are using Nuxt v3.8.0. On trying to initialise the library in Nuxt solution we am getting different errors. I've tried everything I could and I can't seem to figure out what I'm doing wrong. in nuxt.config.js we defined the modules:
modules: [
'@nuxtjs/i18n',
'./modules/01_defineRuntimePlugins',
'nuxt-primevue',
'@pinia/nuxt',
],
modules: [
'@nuxtjs/i18n',
'./modules/01_defineRuntimePlugins',
'nuxt-primevue',
'@pinia/nuxt',
],
I then continue to define the configuration for i18n as so:
i18n: {
defaultLocale: 'nl-be',
locales: [
{ code: 'nl-be', name: 'Nederlands (België)', file: 'nl-be.js', dir: 'ltr' },
{ code: 'fr-be', name: 'Français (Belgique)', file: 'fr-be.js', dir: 'ltr' },
{ code: 'en-be', name: 'English (Belgium)', file: 'en-be.js', dir: 'ltr' },
{ code: 'fr-fr', name: 'Français (France)', file: 'fr-fr.js', dir: 'ltr' },
{ code: 'en-fr', name: 'English (France)', file: 'en-fr.js', dir: 'ltr' },
strategy: 'prefix',
lazy: true,
vueI18n: './nuxt-i18n.js',
},
i18n: {
defaultLocale: 'nl-be',
locales: [
{ code: 'nl-be', name: 'Nederlands (België)', file: 'nl-be.js', dir: 'ltr' },
{ code: 'fr-be', name: 'Français (Belgique)', file: 'fr-be.js', dir: 'ltr' },
{ code: 'en-be', name: 'English (Belgium)', file: 'en-be.js', dir: 'ltr' },
{ code: 'fr-fr', name: 'Français (France)', file: 'fr-fr.js', dir: 'ltr' },
{ code: 'en-fr', name: 'English (France)', file: 'en-fr.js', dir: 'ltr' },
strategy: 'prefix',
lazy: true,
vueI18n: './nuxt-i18n.js',
},
Translation files in the i18n/locales/ folder (nl-be.js):
export default defineI18nLocale(async (locale) => {
return {
welcome: 'Welkom, Welkom!',
}
})
export default defineI18nLocale(async (locale) => {
return {
welcome: 'Welkom, Welkom!',
}
})
At the same level as the nuxt.config.js file, I have the nuxt-i18n.js file defined as so:
export default {
datetimeFormats: {
'en-be': {
short: { year: 'numeric', month: 'short', day: 'numeric' },
},
'nl-be': {
short: { year: 'numeric', month: 'short', day: 'numeric' },
},
},
}
export default {
datetimeFormats: {
'en-be': {
short: { year: 'numeric', month: 'short', day: 'numeric' },
},
'nl-be': {
short: { year: 'numeric', month: 'short', day: 'numeric' },
},
},
}
After then starting the Nuxt project, i get this error: ERROR Cannot start nuxt: Cannot create property 'locales' on string '[object Object]' So I tried pasting the object directly in the vueI18n instead of the path to the file, and when doing so, I receive the error: ERROR Cannot start nuxt: input.replace is not a function I am completely out of idea's, I got no idea what I need to do to solve this issue. Any help is greatly appreciated!
6 replies