Dynamically fetch locales

Is there a way to dynamically fetch the active locales in a Prismic repo?

It seems redundant to have to hardcode the same values in the plugin configuration for the available locales:

I’m using gatsby-source-prismic-graphql but I couldn’t find any way to do this outside of the plugin either, i.e. even a manual fetch request to the Prismic API.

1 Like

Hello @sean!

The screenshot does not show your entire config, but i can see you’re dynamically generating pages.

If you add a &lang argument into your template queries, and then configure the route of the page to add /lang to the URL route, pages will be generated for every language. Read How to dynamically query documents by language and also take a look at this Multi-language website example with Gatsby.js that shows you how to do it.

Also, the options.lags parameter is the configuration that the plugin needs in order to know how many and which languages your project/repository has. It only needs to be added once, or every time you add a new language.

This issue has been closed due to inactivity.

Hey, @paulina.gavilan I don't think this answer solves @sean problems. I think he's looking for a list of languages that are used in the repository. Can you confirm @sean

We do provide this list through the /api endpoint of our API. If you query this endpoint you'll get the list of languages used in your prismic repository. I don't think the gatsby-source-prismic-graphql plugin supports the dynamic fetching of those languages. So you could maybe do a PR to support this.

Does that answer your question ?

1 Like