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

Getting an item by other than default locale slug #231

Open
GreenberryServiceAccount opened this issue May 9, 2024 · 1 comment
Open

Comments

@GreenberryServiceAccount

I'm currently migrating from gatsby-source-datocms v4 to v5, but I'm having some trouble getting it to work. My default locale in DatoCMS is "en" and the other locale I'm using is "nl". In the previous version I could fetch an item based on the "nl" slug, but that doesn't seem to work in version 5 anymore. This should really be possible, because if, for example, I'm navigating to /nl/nieuws/mijn-eerste-nieuws I only know that my Dutch slug is mijn-eerste-nieuws. I don't have the "original" English slug at my disposal. Some items don't even have an English version.

I've verified that this issue exists by using the graphql explorer locally at http://localhost:8000/__graphql, by first getting an article in Dutch by using the English slug, eg:

query getArticle {
  data: datoCmsArticle(
    slug: { eq: "my-first-article" }
    locale: "nl"
  ) {
    title
    slug
    intro
    date
  }
}

This gives me the correct article in Dutch, so the "locale" argument is working.

I don't get any response when I try to use the Dutch slug however, eg:

query getArticle {
  data: datoCmsArticle(
    slug: { eq: "mijn-eerste-artikel" }
    locale: "nl"
  ) {
    title
    slug
    intro
    date
  }
}

Am I missing something? There must be a way to get a specific article based on the slug in any translation, right?

@GreenberryServiceAccount
Copy link
Author

Update: I've now changed everywhere in my project to include the item's id in the object that's passed as context argument into the createPage function from Gastby. I've updated all queries to fetch the CMS item based on the id instead of the slug now and it works.

For me now this problem is solved, but it still seems like something you should be able to do: fetch a CMS item based on their slug in another language than English...

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

1 participant