REST API params to look for slug in multi locales

Hey!

We have a mutli-language website we are currently building and we have slugs in multiple languages (en-US, en-DE and de-DE) I’m now looking for an API Query to pass which is basically looking for a matching slug in either of those languages (preferably the currently visited language first and afterwards the fallback). So basically I just want to apply the regular fallback logic also to the Query params. I tried various options but can’t find a solution to this problem, does any know if it’s possible?

Example set up: (en-US is the default and both en-DE and de-DE have en-US as the fallback)

  • slug en-US: “english-article”
  • slug en-DE: “”
  • slug-de-DE: “german-article”

Now I want to use the de-DE slug to get to the sys.id:
.../entries?content_type=article&fields.slug[in]=german-article
.../entries?content_type=article&fields.slug.de-DE[in]=german-article

^ The first one doesn’t work, but the second one does. So far so good.
What now happens though if I use the same logic with the locale en-DE is that it’s breaking because I specifically told it to look in the en-DE, but it’s empty. Now only the first one works.

.../entries?content_type=article&fields.slug[in]=english-article
.../entries?content_type=article&fields.slug.en-DE[in]=english-article

So in theory I would love to have a logic like this:
.../entries?content_type=article&fields.slug[en-US,en-DE][in]=english-article or
.../entries?content_type=article&fields.slug[en-US,de-DE][in]=german-article

Okay, I now did it differently. So if anybody finds this thread here’s how I resolved it:

In my code I have a foreach for every possible locale and I’ll only grab the ID of the Request to make them quicker, so for example:

  1. /entries?content_type=article&fields.slug.de-DE[in]=german-article&fields.publishedLocales[in]=de-DE&select=sys.id&limit=1
  2. /entries?content_type=article&fields.slug.en-DE[in]=english-article&fields.publishedLocales[in]=en-DE&select=sys.id&limit=1

Afterwards I have one or two IDs. One ID if the article’s slug is translated like in my example. If the slug would be the same in DE and EN, the result would be two IDs which are identical. I’ll save them and end up with this setup:

[id1, undefined] or [undefined, id2] or, if the slug would be identical, this [id1, id2]. But id1 and id2 should be equal, otherwise you’d grab another article by this point.

So far so good, now I filter out the undefined values (could be more if I’d check for more languages of course) and let the first valid ID be the ID of my choice. At this point I can be very certain that the ID is the one I actually want.

In the end I use this ID to do another API call and the problem is resolved, but I still have to do two API calls unfortunately. We build it in the Nuxt.js Project so that the server is doing both calls at once and the client only does on API call in the end.

Hope this will help anyone in the future.