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

withAllLocales doesn't query on all locales. #2196

Open
votemike opened this issue Mar 28, 2024 · 7 comments
Open

withAllLocales doesn't query on all locales. #2196

votemike opened this issue Mar 28, 2024 · 7 comments

Comments

@votemike
Copy link

Expected Behavior

Querying with withAllLocales should query on all translations.
E.G.

await client.withAllLocales.getEntries<
  TypePageSkeleton | TypePostSkeleton
>({
  content_type: 'page',
  'fields.url': url,
  include: 10,
  limit: 1,
});

Should return my results for any localised url.

Actual Behavior

The query mentioned above only works if querying url specified in the default locale language.

Possible Solution

Steps to Reproduce

Set up Contentful with a default language and a language that falls back to the default language.
Create a model with a translatable URL field.
Add an entry with with only a url in the default language
Add an entry with with a url in both languages
Query based on non-default url.

Context

I have several pages that can be in several languages.
Sometimes I want all languages to use the same URL.
Sometimes I want each language to have a unique URL.
I want to retrieve the page by URL.
I cannot pass the locale in to the query, as locales with no URL translation will not fallback to the default language url for querying purposes.

Environment

  • Language Version:
  • Package Manager Version:
  • Browser Version:
  • Operating System:
  • Package Version: 10.6.22
  • Which API are you using?:
@rfearing
Copy link

rfearing commented Mar 29, 2024

I'm having the same problem: V 10.7.0 (and in latest)

@rfearing
Copy link

rfearing commented Mar 29, 2024

@votemike I figured out my issue. I had to continue digging down into the nested fields. Our Page content model has a content field. The localized content is nested in that content field. That means we had to dig deeper to get our localized fields e.g.

entry.fields.content['en-US'].fields.title['pt-BR']

I hope maybe that helps but not sure if it's the same for you.

@votemike
Copy link
Author

@votemike I figured out my issue. I had to continue digging down into the nested fields. Our Page content model has a content field. The localized content is nested in that content field. That means we had to dig deeper to get our localized fields e.g.

entry.fields.content['en-US'].fields.title['pt-BR']

I hope maybe that helps but not sure if it's the same for you.

Is that while you are querying the API?

@rfearing
Copy link

rfearing commented Apr 1, 2024

Yeah, so entry is a result of mapping items from:

const {items} = await this.client.withAllLocales.getEntries<PageEntrySkeleton>(query)

@votemike
Copy link
Author

votemike commented Apr 1, 2024

So what query are you using to query the pt-BR title?

@rfearing
Copy link

rfearing commented Apr 2, 2024

const query = {
    content_type: 'page',
    'fields.path': path,
    include: 5,
    limit: 1,
}

This get's our Page and child models, then entry is items[0]

@votemike
Copy link
Author

votemike commented Apr 2, 2024

Ahh, so you query by path (which I guess is the same in all locale's) and then choose the pt-BR localisation of the title.

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