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

ContentQuery locale does not work #1737

Closed
KhaledAlMana opened this issue Dec 10, 2022 · 5 comments · Fixed by #1748
Closed

ContentQuery locale does not work #1737

KhaledAlMana opened this issue Dec 10, 2022 · 5 comments · Fixed by #1748

Comments

@KhaledAlMana
Copy link

KhaledAlMana commented Dec 10, 2022

Environment

  • Operating System: Darwin
  • Node Version: v16.18.1
  • Nuxt Version: 3.0.0
  • Nitro Version: 1.0.0
  • Package Manager: yarn@1.22.19
  • Builder: vite
  • User Config: modules, runtimeConfig, ssr, app, css, build, experimental, components, vite, intlify, vueuse, windicss, content, openidConnect
  • Runtime Modules: nuxt-windicss@2.6.0, @intlify/nuxt3@0.2.4, @vueuse/nuxt@9.6.0, @nuxt/content@2.2.0, @pinia/nuxt@0.4.6, nuxt-openid-connect@0.4.2, unplugin-icons/nuxt
  • Build Modules: -

Reproduction

Reproduction: https://stackblitz.com/edit/github-jzx7nq
locale property within component does not filter.
locale within where property does not seem to be working as well

const locale = 'ar-SA';
<ContentQuery
  v-slot="{ data }"
  :path="$route.path"
  :find="undefined"
  :locale="locale"
> 
      {{ $route.path }}
      {{ locale }}
      {{ data }}
</ContentQuery>

Describe the bug

Objective:
I have multilingual posts that I need to filter based on user's language.

Bug:
locale property does not work for other than defaultLocale

Additional context

I cannot seem to find enough info about filtering locale in docs or issues
I tried everything in docs, but things seems to be breaking.
For example:
<template #empty>
<template #not-found>
does not work with ContentQuery, unlike what docs says here

UPDATE 1 [10-DEC-2022]:
The below function is the only working locale filtration
const content = await queryContent(query).locale(locale).findOne();

Logs

No response

@KhaledAlMana
Copy link
Author

KhaledAlMana commented Dec 10, 2022

Somehow it worked for me by adding the where property as the following

<template>
  <PageWrapper class="flex flex-col">
    <ContentQuery
      :path="$route.path"
      :locale="locale"
      find="one"
      :where="{ _path: { $eq: $route.path } }"
    >
      <template #default="{ data }">
        <PageHeader>
          <PageTitle :text="data.title" />
        </PageHeader>
        <PageBody>
          <PageSection>
            <ContentRenderer :value="data" />
          </PageSection>
        </PageBody>
      </template>
      <template #empty>
        <h1>Post in empty</h1>
      </template>
      <template #not-found>
        <Error :code="404" wrap />
      </template>
    </ContentQuery>
  </PageWrapper>
</template>

@KhaledAlMana
Copy link
Author

:locale is not documented to be used within ContentList but this works just fine.

      <ContentList
        v-slot="{ list }"
        :query="{
          where: { _path: { $ne: $route.path } },
          limit: 5,
          sort: { date: -1 },
        }"
        :locale="locale"
      >
...

Copy link
Member

@KhaledAlMana Could you check edge-channel to confirm that is solved or not?

@KhaledAlMana
Copy link
Author

@farnabaz I will check and get back to you.

@KhaledAlMana
Copy link
Author

@farnabaz Thanks a lot! it works just fine.
Tested Here

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

Successfully merging a pull request may close this issue.

2 participants