-
-
Notifications
You must be signed in to change notification settings - Fork 642
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
Content and i18n - Document not found for non-default locales #2596
Comments
I have the same experience. Detailed explanation: nuxt/nuxt#26699 |
ContentDoc problemIf we use
it is working with only default language. Child code [id].vue
Even if we provide path:
it is not working. Renderes only default language and cant see de/gallery/001 or de/gallery/001. When we don't add content part to
works nicely. QueryBuilderParamsIf we place locale info into nuxt.config.ts
Than I expect that following code:
will give me results for every locale. However it works only with default locale. CodeProject with bug - with locales in content part of nuxt config:
Working project - without locales in content part of nuxt config and dynmyc paths: |
Nuxt content is not compatible with i18n module at the moment. |
Look here - https://github.com/RollingTL/Image-gallery-nuxt3-i18n/tree/test-content-no-config Agree that Nuxt content devs are not very active. |
My solution is also removing locale config in nuxt content. Don't add the following
and using ContentRenderer to render the content based on the locale folder.
<script setup lang="ts">
const route = useRoute()
const { locale } = useI18n()
/**
* @docs queryContent https://content.nuxt.com/composables/query-content
*/
async function fetchContent() {
try {
return await queryContent(locale.value.toLowerCase(), route.path).findOne()
} catch (err: any) {
return await queryContent(route.path).findOne()
}
}
/**
* @docs https://nuxt.com/docs/api/composables/use-async-data
*/
const { data } = await useAsyncData('content', () => fetchContent(), {
watch: [locale],
})
</script>
<template>
<main class="py-5 px-5 sm:px-10 break-words">
<ContentRenderer class="prose prose-zinc" :value="data">
<template #empty>
<p>Stay tuned; it will be added later 😉</p>
</template>
</ContentRenderer>
</main>
</template>
This is my nuxt.config content: {
highlight: {
theme: 'github-dark',
langs: ['json', 'js', 'ts', 'html', 'css', 'vue', 'shell', 'mdc', 'md', 'yaml', 'solidity'],
},
},
i18n: {
vueI18n: './i18n.config.ts',
strategy: 'no_prefix',
locales: [
{
label: 'English',
code: 'en',
iso: 'en',
},
{
label: '繁體中文',
code: 'zh-TW',
iso: 'zh-TW',
},
],
}, My project is at https://vuedapp.xyz |
This solution worked for me only after setting prerender to true for the routes. |
@johnson86tw interesting. I've initially set it up just like you did here. GitHub didn't build it. Either way, none of them build. Assuming this gets fixed with fi3ework/vite-plugin-checker#327 and updating vue-tsc to 2.x and Typescript to 5.5.x, which version would be better? Is there actually a difference? |
Hello, I have a module called nuxt-i18n-micro, and I’ve added an integration example with Nuxt Content: |
Discussed in #2595
Originally posted by vlamic March 25, 2024
Hi,
I'm trying to setup a project which is driven by content and supports multiple languages, so I have created two dirs in my
content
folder:en
andes
. When I try to access the default routes (e.g. http://localhost:3000/ or http://localhost:3000/about), it loads the pages correctly. However, when I try to access non-default pages, it's not able to locate the content (e.g. http://localhost:3000/en/about or http://localhost:3000/en). Am I missing something?I have uploaded a sample project here: https://github.com/vlamic/content-app-test
Content structure:
Pages structure:
Nuxt config:
Thank you!
The text was updated successfully, but these errors were encountered: