i18n icon indicating copy to clipboard operation
i18n copied to clipboard

How to translate routes without using locale prefix

Open jonalxh opened this issue 5 years ago • 19 comments
trafficstars

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'
    }]
]

jonalxh avatar May 26 '20 19:05 jonalxh

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.

rchl avatar May 26 '20 19:05 rchl

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.

jonalxh avatar May 26 '20 19:05 jonalxh

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?

jonalxh avatar May 26 '20 19:05 jonalxh

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.

rchl avatar May 26 '20 20:05 rchl

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.

jonalxh avatar May 26 '20 22:05 jonalxh

Yes, I've confirmed that in my previous comment and said that I'll look into it.

rchl avatar May 27 '20 04:05 rchl

Yes, I've confirmed that in my previous comment and said that I'll look into it.

Thanks, I'll be waiting for it.

jonalxh avatar May 27 '20 04:05 jonalxh

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.

jonalxh avatar Jun 02 '20 14:06 jonalxh

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.

rchl avatar Jun 02 '20 15:06 rchl

Thanks, I'll be trying while you have some time.

jonalxh avatar Jun 02 '20 18:06 jonalxh

Any updates on this? 🙂

thomas4Bitcraft avatar Jun 18 '20 07:06 thomas4Bitcraft

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.

stale[bot] avatar Aug 17 '20 11:08 stale[bot]

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.

stale[bot] avatar Oct 16 '20 18:10 stale[bot]

Any updates?

jonalxh avatar Oct 16 '20 18:10 jonalxh

Only can reply with this: https://blog.sindresorhus.com/issue-bumping-e3b9740e2a0

rchl avatar Oct 18 '20 18:10 rchl

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.

existe-deja avatar Feb 26 '21 15:02 existe-deja

Any chance for improving and making it possible? (somewhat a key feature in a project I develop)

whooof avatar May 07 '21 16:05 whooof

+1

rttmax avatar Feb 25 '22 12:02 rttmax

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.

Expanddigital avatar Oct 05 '22 08:10 Expanddigital