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
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.
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.
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.