Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace NuxtLink with NuxtLinkLocale to support i18n prefix strategy (lang slug in path) #134

Open
xairoo opened this issue Feb 28, 2024 · 1 comment

Comments

@xairoo
Copy link

xairoo commented Feb 28, 2024

I just batch replaced all NuxtLink entries with NuxtLinkLocale to support the prefix strategy of i18n.

i18n: {
  strategy: 'prefix',
},

Works! When you set no_prefix the lang slug will be gone.

Btw. is it on the roadmap to create translated slugs? Like /products > /produkte (not for the specific product name, just generic stuff like about > ueber and so)? I have done that with a Next.js project because of SEO but I am totally new to Vue.js but I am sure this will work too =)

@AndreasMueck
Copy link

AndreasMueck commented Jun 3, 2024

For translating routes insert following example object into i18n in nuxt.config.ts:

        // 👇 custom names für routen in anderen sprachen
        customRoutes: 'config',
        strategy: 'prefix_except_default',
        baseUrl: 'https://woonuxt.dvl.to/', // Your woonuxt installation
        pages: {
            about: {
                de_DE: '/ueber-uns',
                en_US: '/about-us',
            },
            privacy: {
                de_DE: '/datenschutzerklaerung',
                en_US: '/privacy-policy',
            },
        },

The first keys below pages are the pages names. Please replace the routes (about, privacy) with your own ones.

In the menu component you have to replace the links as well (for example):

<script setup>
const localePath = useLocalePath();
</script>

<template>
<NuxtLink :to="localePath({ name: 'index' })">{{ $t('messages.general.home') }}</NuxtLink>
<NuxtLink :to="localePath({ name: 'products' })">{{ $t('messages.general.allProducts') }}</NuxtLink>
...
...

I think that's all you need for translating routes.
BUT beware, this will not work with strategy: no_prefix (afaik)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants