Trouble getting multilingual content

Hi everyone !
I have some trouble when i try to fetch documents in locales that are different from the main "language (fr-fr)".

  • When i fetch a document by id (id of the document in the main language) with the option {lang: *} , in the "alternate_languages" key in the result, i can find information like id, lang, uid, type, but there is no data.
  • When if then fetch the document in another language than the main language (using its id, or its uid), i have no results (empty array)
    Here is my repository : https://eggs.prismic.io/api
    even when i search for all documents in the api i dont find any document in other languages.
    but everything seems to be ok in my repository. document are published and marked as live.
    Please, can you help ?
    Thank in advance.

Hi @tutanck, hopefully we can sort this out for you :slightly_smiling_face:

  1. When you query a document, the alternate_languages array will only contain the meta data for the documents (ID, lang, UID, etc.). So it’s normal that there is no data there.

  2. Can you show me the query you are running when you don’t get any results? You might need to put the asterisk in quotes: { lang: '*' }

Hi. okay. I understand but there is still a problem. I don’t have any result when i fetch by id (of the document written in a locale) .
My App is a simple translation app.
Here is an extract of my “prismic-toolbox.js” file with a custom method to fetch a “phrase’s translation infos (metadata)” : getPhraseTranslationInfosByLang. and a method to fetch a phrase : getPhrase.

And here is my
fetchTranslation method that call getPhraseTranslationInfosByLang and then try to fetch the ‘translated’ phrase by its id (with getPhrase).
When i fetch a ‘translated’ phrase by its id i get an empty result array.
Even when i just call directly getPhrase(“XvtsRBUAACgAb6Sp”) where “XvtsRBUAACgAb6Sp” is the id of a ‘phrase document’ in the local ‘en-us’ i have no results. But when i call getPhrase with the id of the french version (fr-fr) of the same document, everything work well.

You will find a sreenshot attached.

Thanks a lot for your help.

I took a look and think I know what the issue is here. Even when you query by ID like this, you need to specify the language code or the wildcard '*'. If you don’t specify a lang, then the API will always assume that you’re querying for documents in the main language. This is why it works for your fr-fr document but not your en-us one.

I think all you need to do to make this work is to add the { lang: '*' } query option to this query and it will work as you expect.

Thank you very much :pray: :pray: :pray: it works just fine !
i thought that by default prismic would assume a defaul value of { lang: '*' }

Yeah, it might not be obvious but if you don’t specify a language, then Prismic queries the main language by default.

I’m happy that we were able to sort it out for you :slightly_smiling_face:

1 Like