Query by language
If you are taking advantage of the Localization feature in your Prismic repository, then you'll need to be able to query documents by a specific language. This page will show you how retrieve documents by language.
Before Reading
This page assumes that you've already imported the Prismic library and retrieved the Client object. If you want to learn how to do this, then refer to the How to Query the API page.
To specify a particular language you want in a query, simply add the lang option set to the language code you are querying (example: "en-us" for American English).
If you don't specify a "lang" the system will by default query the documents in your master language.
Here's an example of how to query all the documents of the type "blog-post" in Traditional French ("fr-fr").
client.query(
Prismic.Predicates.at('document.type', 'blog_post'),
{ lang : 'fr-fr' }
).then(res => {
// res is the response object, res.results holds the documents
})
If you want to query all the document of the same type in all languages you can just add the wildcard value '*' as your lang option.
Here is an example that queries all the documents of the type "blog_post" in all the available languages.
client.query(
Prismic.Predicates.at('document.type', 'blog_post'),
{ lang : '*' }
).then(res => {
// res is the response object, res.results holds the documents
})
To learn more about how to query your documents by UID and language, check out the Query by ID and UID page.