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.