Get All Languages from Settings via API

Is it possible, with the Javascript API, to get the list of languages set up in a Prismic repo in Settings > Translations & locales (Multi-languages – /settings/multi-languages/)?

It would be awesome if the language name, code, and icon were available.

Hello Chris,

Thanks for posting to us.

When you query the API for the Document object or the Response object, you get all the available languages in two fields: lang and alternate_languages. You can get only language code through this like fr-fr or en-gb.

Please find more details here.

Let me know if you have any other doubt.

Best
Priyanka

Hi,

Yes, I'm aware of the Document and Response Object, but I'm wondering if there's a query to get the list of languages that are set up in the Settings area of the Dashboard/Repo. I just want a list of the languages set up in the repo, not the languages set for each document. Does that make sense?

Hello @chris.davis

This is not possible directly for the moment, there is no direct query possible for getting results. Although, there is a workaround like you can get all the languages of all the documents in JSON, using the following query:

query{
  _allDocuments{
    edges{
      node{
        _meta{
          lang
        }
      }
    }
  }
}

After getting results in JSON, you can avoid duplicates, using the map or some other function on the lang field of JSON.

Here's Prismic's Graphql documentation.

Let me know if you have any doubt.

Best,
Priyanka

Ok, thank you very much.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.