i18n
i18n copied to clipboard
How to translate routes without using locale prefix
hI, I'm trying to do an app which works in Spanish and English, I need it can be accesed with page name and translated name, i.e: I have about.vue in pages folder and I need to access it with /about and /nosotros. I've tried with your plugin but it causes an /es/nosotros route and I need it to work without locale prefix.
Adding no_prefix strategy to nuxt-i18n config in nuxt.config.js doesn't work too.
I've set the following code in about.vue without success:
export default {
nuxtI18n: {
paths: {
es: '/nosotros',
en: '/about'
}
},
}
nuxt.config.js:
modules: [
['nuxt-i18n', {
strategy: 'no_prefix',
lazy: true,
parsePages: false, //Tried with true and does not work
locales: [
{
name: 'Español',
code: 'es',
file: 'es/locale.json'
},
{
name: 'English',
code: 'en',
file: 'en/locale.json'
}
],
langDir: '/locales/',
defaultLocale: 'en'
}]
]
With no_prefix no prefixes are created.
The about.vue snippet also seems correct.
You must be doing a simple mistake somewhere if that doesn't work. Please create reproduction on github or https://codesandbox.io/ if you want me to look at it.
Do you have a working example for me to try before creating the code snippet? Please.
Additionally I should tell you I am migrating a Vue project into Nuxt and I used to use vue-i18n if it is important to you.
I was reading this article and it says no_prefix does not work with Custom Routers. What should I do to correctly translate my routes?
Here is some example you can fork and modify: https://codesandbox.io/s/i18n-plugin-i18nlocales-ouwhn
I was reading this article and it says no_prefix does not work with Custom Routers.
Ah yes, that's true.
To be fair not sure why. I think it might still be possible to support custom routes with no_prefix strategy. I could have a look at that at some point.
Looking at the example you gave me, using no_prefix only keep the same initial route, so if I have /about it will be the same in Spanish and English, I'd like it to change the current path by the custom path specified in about.vue:
nuxtI18n: {
paths: {
es: '/nosotros', //Set it on language change
en: '/about'
}
},
Is it possible or nothing to do?
I thought switchLocalePath would be the trick, but it does not work when no_prefix enabled.
Yes, I've confirmed that in my previous comment and said that I'll look into it.
Yes, I've confirmed that in my previous comment and said that I'll look into it.
Thanks, I'll be waiting for it.
Hi. Is there any progress with this? I'm actually working in a project and it is an important part. Maybe could you give me some ideas to make it work?
Thanks a lot.
I've looked into it but unfortunately, it would require more work than I've anticipated. It would require solution similar to what #710 and #641 require. So I don't think I can do a quick fix here.
Thanks, I'll be trying while you have some time.
Any updates on this? 🙂
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Any updates?
Only can reply with this: https://blog.sindresorhus.com/issue-bumping-e3b9740e2a0
If this feature is mandatory to go online, a workaround is to start as many servers as you have different languages. This way you can take advantage of prefix_except_default strategy.
Any chance for improving and making it possible? (somewhat a key feature in a project I develop)
+1
Can't believe this still isn't fixed, kind of a key features for most software. Why would you use a prefix if you are going to translate the slugs.