i18n fallback issues
Heya people. I've recently moved away from NextJS over to Vue and I'm trying to setup the most important things and one of them is i18n. It works so smoothly compared to next and I love it so far. One thing I am not happy with though is the fallbackLocale feature on the i18n package. The documentation says I should do it in this way but the editor says it is wrong. Any ideas?
Documentation says I should it like this:
But I get the error:
^ On line with "fallbackLocale"
Any suggestions? 😄
21 Replies
See. You always solve it after asking the community. In case anyone else runs into the same issue, remove "defineNuxtConfig" so it says "export default { ...." instead.
New issue..
So I was able to set the fallback locale but that doesnt seem to solve this. I have not setup the finish language yet and therefore I want it to fall back to english. Any suggestions on why this occurs?
I still have the same error as above. Yes, I was able to set the fallbackLocale without my IDE complaining but it actually never worked.
@Polak just create file i18n.config.ts
and add inside
export default {
fallbackLocale: ['en'],
};
Hey @xibman. I just tried but it still seems like it doesnt work. After visiting /fi/teams I still get 404 instead of being redirected to /teams.
At least it is not longer complaining so thank you very much for that but seems to not work yet. :/
can you share the config you have in nuxt.config.ts for i18n
Yeah.
and in /i18n.config.ts
{
code: "en",
iso: "en-US",
name: "English",
file: "en-US.json"
},
Add isCatchallLocale: true
you can remove vueI18n: './i18n.config.ts' is automatic
add to i18n in jnuxt config
detectBrowserLanguage: {
useCookie: true,
redirectOn: 'root', fallbackLocale: 'en, },
redirectOn: 'root', fallbackLocale: 'en, },
Tried doing a gif to show the exact issue.
Still error on /fi
reboot you server after thge change
Still error. Cursed as hell haha.
you want to be redirected on a default language if this one does not exist
yeah
i think you need to have your own guard on this !
because for sure the page does not exist
that's why you end on 404
nuxt i18n generate routes based on available languages
or add this kind of fallback
fallbackLocale: {
'de-CH': ['fr', 'it'],
'zh-Hant': ['zh-Hans'],
'es-CL': ['es-AR'],
es: ['en-GB'],
pt: ['es-AR'],
default: ['en', 'da']
}
try
fallbackLocale: {
'fi': ['en'],
default: ['en']
}
just to confirm !
No luck sadly. COULD it be that it doesnt listen to i18n.config.ts? you say it is auto imported but maybe my stuff is cursed? I might have set it up wrong maybe
Configuration for createI18n can be passed using a configuration file. By default, the module will scan for a i18n.config{.js,.mjs,.ts} if nothing is specified.
nuxt i18n will only generate route for the locales you have on locales array
Oh okay. In that case an error must be given to people who tries and visit a language that doesnt exist. Thanks for your help. Real champ!
You're welcome