Can't retrieve documents from alternative locale

Hi there,

I'm using Nuxt and Slice Machine for my project. I have one main locale, which is Dutch and a secondary locale, which is English. For my reservations page I use the Dutch uid 'reserveren' and the English uid 'reservations'.

When I call the slice-zone all goes well for both locales. But when I try to retrieve the document in asyncData it only returns a document on the Dutch page. On the English page it returns undefined. I use the following code:

async asyncData({ $prismic, params }) {
    const result = await $prismic.api.getByUID('page', params.uid)
    return {document: result}
  }

Am I doing something wrong? Thanks already!

Hi @hedzer. I think all you need to do is to add the language query option and this should work:

async asyncData({ $prismic, params }) {
  const result = await $prismic.api.getByUID('page', params.uid, { lang : 'en-gb' })
  return {document: result}
}

You don’t need to add the language query option to retrieve documents in your main locale (Dutch) but you do need to include it to retrieve documents in any other locale.

That was the problem, thank you very much Levi!

1 Like

@hedzer You are very welcome :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.