nuxt-modules / i18n

I18n module for Nuxt
https://i18n.nuxtjs.org
MIT License
1.75k stars 483 forks source link

Custom routes issue with switchLocalePath #2033

Open simoroma opened 1 year ago

simoroma commented 1 year ago

Environment

"@nuxtjs/i18n": "^8.0.0-beta.10",

Reproduction

I have the following pages:

and my nuxt.config.ts has the following:

        customRoutes: 'config', // disable custom route with page components
        pages: {
            terms: {
                fi: '/terms-fi',
            },
        },

It works correctly when going from Finnish to English. Though when I am at /fi/terms-fi (the Finnish page) and I switch to english with switchLocalePath the routes becomes terms-fi and it should just be terms

Describe the bug

Error in the route when switching language if custom pages are defined.

Additional context

No response

Logs

No response

riddla commented 1 year ago

Probably because the name of your page (terms-fi.vue) is equal to the path you provide via the pages config (/terms-fi).

Why do you have two pages for terms? What do you want to achieve?

simoroma commented 1 year ago

Thanks for the reply. I am trying to get something similar to this: https://i18n.nuxtjs.org/custom-paths/ It is just more convenient to have two pages for terms because they have some paragraphs and I don't want to define many variables and get translations for each variable via $t.

I tried different variations of this. I still have the same issue with:

customRoutes: 'config', // disable custom route with page components
        pages: {
            terms: {
                en: '/terms',
                fi: '/terms-fi',
            },
        },
riddla commented 1 year ago

I don't think you can achieve that with nuxt-i18n (easily). The customs paths are meant to provide the paths to one single page.

It's actually quite common to have a lot of translated paragraphs (respectively variables) in pages. Maybe the tooling around vue-i18n over at https://kazupon.github.io/vue-i18n/guide/tooling.html can help you translate/work faster? I am using https://www.codeandweb.com/babeledit and https://marketplace.visualstudio.com/items?itemName=lokalise.i18n-ally to speed things up.

simoroma commented 1 year ago

Cool stuff. I might try to use them then.

I wanted to have two template files so I could send them to the website owner: eg terms-en.vue and terms-fi.vue. Then they would do the translations.

riddla commented 1 year ago

BabelEdit can read your vue-i18n language files and export them to a CSV file. Hand it over to your client and import it again when they are finished translating. This is a quite convenient workflow, we have used them in several Nuxt (2) projects.