Templating Multi-language info

This page shows you how to access the language code and alternate language versions of a document.


Before Reading

This article assumes that you have saved the document object in a variable named document as shown in the Retrieve the document object page.

Get the document language code

Here is how to access the language code of a document queried from your Prismic repository. This might give "en-us" (American english), for example.

Copy
const language_code = document._meta.lang;

Get the alternate language versions

Next we will access the information about a document's alternate language versions. You can loop through the alternate_languages array and access the id, uid, type, and language code of each as shown below.

Copy
document._meta.alternateLanguages.forEach(altLang => {
  const id = altLang.id;
  const uid = altLang.uid;
  const type = altLang.type;
  const lang = altLang.lang;
});