Rendering Multi-language Info
This page shows you how to retrieve the language code and alternate language versions of a document.
Before Reading
This page assumes that you have retrieved your content and stored it in a variable named document.
Here is how to retrieve the language code of a document queried from your Prismic repository. This might give "en-us" (American english), for example.
Copy
const language = document.lang;
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.alternate_languages.forEach(function(altLang){
var id = altLang.id;
var uid = altLang.uid;
var type = altLang.type;
var lang = altLang.lang;
});