-
Notifications
You must be signed in to change notification settings - Fork 22
Only generate the site for the language set in DEFAULT_LOCALE #134
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
Comments
I don't really understand the issue. no_prefix physically can't create all the pages for both languages. When no_prefix is used, there is no modification of the routes at all, and the routing logic is taken from Nuxt. The locale is passed simply via the defaultLocale parameter (I hope you're changing defaultLocale before running generate?). Please provide a simple example—maybe then I'll be able to understand it better. |
I researched some more. When having $defineI18nRoute on contact.vue:
It will generate the other language page even if DEFAULT_LOCALE is set. |
So this is completely expected behavior. How else do you imagine switching the language in no_prefix mode? The router needs to know all the links that can be navigated to, even if a different locale is set. The module generates all possible links, and the router manages navigating to the required page. |
By creating two different The language switcher is an actual "domain switcher" which points to another TLD. So changing the DEFAULT_LOCALE would create the correct language on index and the translated links + pages. Otherwise I would need to have two different repos (+1 for each language) for the same website, or all websites would have the same content accessable by sitemap. |
In version v1.77.0, a new parameter called noPrefixRedirect was added link. If you enable it, it will set up a redirect instead of the standard routes. Please give it a try. In the future, be sure to describe your problem in detail and provide an example. |
Well I did. I didn't know what was causing it. But this change redirects it to 404 and instead redirects it to the other language. It should be reversed to redirect it to the generated language. Maybe another solution would be to filter out all routes in $defineI18nRoute that do not match the locale before crawling? |
Provide an example project with reproduction steps. |
Here: I have a suspicion there is a problem with paths on the disk. I am running Git bash on Windows. If you are not getting these problems I assume you are on another OS.
Notice "contact/" directory which is incorrect. Should be "kontakt/" I think this line might be a problem, but I have been unable to find the issue: Line 47 in 311bcf7
or this: Line 276 in 311bcf7
Because isCustom is false in: nuxt-i18n-micro/src/page-manager.ts Line 299 in 311bcf7
When I:
Please confirm correct output. Can you advice on how to install nuxt sitemap for testing in the playground? I get the error:
|
Now I understand the issue; it was indeed related to the OS. I fixed it in version 1.79.0. Please try updating.
Try installing it manually: npm i @nuxtjs/sitemap Or add it to your "devDependencies": {
"@nuxtjs/sitemap": "^7.2.5"
} Then, include it in export default defineNuxtConfig({
modules: [
//...
'@nuxtjs/sitemap',
],
}) If this doesn’t help, it's best to reach out to the developers of |
Thanks, now this URL works, but I found another bug. The translation is redirecting to the defaultLocale, so it will always be english. See the updated repo branch and changes:
If you refresh page you can see it reverting the translation. Another issue, this part in index.vue:
Always overrides the entire object "navigation", it does not merge the keys. Maybe this is intended? But if you add in your Oh and also |
The translation won't be in English if you're visiting the site for the first time. On subsequent visits, the translation will be determined by the no-prefix-locale. For example, if you started in dev mode, changed the language, then switched to production and visited the site, it would use the locale from no-prefix-locale. The same applies if you started in production, changed the language, restarted, and visited again. This behavior is intentional to preserve the user's locale, and it should work this way in production mode.
Unfortunately, there's nothing I can do here—that's the intended behavior. The complex logic for merging objects requires a lot of resources and can cause significant issues. Simply avoid using duplicate paths;
Your links are only generated when the page loads—Vue doesn’t track changes after that. You need to do something like this: <template>
<h1>{{ $t('navigation.title') }}</h1>
<ul class="space-y-0 rounded-xl p-4">
<li
v-for="(link, index) in navLinks"
:key="index"
>
<NuxtLink :to="localeRoute({ name: link.to })">
<span>
{{ link.label }}
</span>
</NuxtLink>
</li>
</ul>
</template>
<script setup lang="ts">
const { localeRoute, $t } = useI18n()
const navLinks = computed(() => [
{
to: 'index',
label: $t('navigation.home'),
},
{
to: 'contact',
label: $t('navigation_component.contact'),
},
])
</script>
<style scoped>
</style> By wrapping |
Something is still bugged. I am using incognito mode so it should be fresh for every visit. I even closed down the browser. I updated the branch: https://github.com/Zyles/nuxt-i18n-micro/tree/no-prefix-redirect-bug
Url: New incognito browser:
Incorrect: Url: Also noted in sitemap.xml it generates urls for both languages when using EN (defaultLocale, fallbackLocale):
Which would be incorrect too. |
Were you able to reproduce my last issue? |
Yes, but I don't have time to fix this now — it's complicated and I’m not sure how to fix it. |
I looked at it again and think I’ve found the main issue. Try version v1.83.2. There are still some problems; for example, a route can be opened by two links if it’s added through localeRoutes. I’ll keep working on it. |
added redirect logic in v1.83.3 |
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
I am using no_prefix strategy with DEFAULT_LOCALE to generate a two language site into static.
Each site has its own TLD specific domain and static repository. So they are completely separated by only changing the translation.
The problem is when running nuxi generate it will create all the pages for both languages, which will be wrong since index will only be in the one language, but with translated subpages.
This will create SEO problems since that will create duplicated content across two sites. Also since using the sitemap plugin with nuxt it will be crawled by search engines even if the links are not active on the generated site.
I think the correct behaviour when using no_prefix strategy in combination with DEFAULT_LOCALE it should only generate the site with the language set in locale, not any translated pages. Or at least have the option to use this behaviour.
The text was updated successfully, but these errors were encountered: