Multilingual FAQ schema with JavaScript: an effective solution for international SEO

Optimizing natural search engine ranking (SEO) today involves integrating structured data into your website. Among the many available markup types, the FAQPage schema is particularly useful for enriching search results on Google and providing users with immediate answers to their queries.
However, when managing a multilingual website, it is essential to present a FAQ adapted to each language to improve the user experience and optimize international SEO. An English-speaking visitor should not see a FAQ in French and vice versa.
In this article, we will explore how to use JavaScript to detect the user’s language and dynamically display the corresponding FAQ schema. We will explain how the code works, why it is useful, and how you can adapt it to your own needs.
The FAQPage schema helps search engines better understand a page’s content and directly display rich snippets under the site link in search results. These enhanced snippets provide additional visibility and improve click-through rates (CTR).
A well-structured schema increases the chances of obtaining prominent positions on Google, particularly in voice searches, where digital assistants often use these data to formulate responses.
Displaying a FAQ in the user’s language provides a smoother and more intuitive navigation experience. A visitor who immediately finds answers in their preferred language is more likely to stay on the site and engage with its content.
By dynamically adapting questions and answers to the user’s linguistic preferences, you avoid comprehension issues and maximize the relevance of the provided information. This also helps boost the credibility and reliability of your site in the eyes of both search engines and visitors.
We will use JavaScript to:
The following script dynamically displays a FAQ based on the browser’s detected language.
<script>
document.addEventListener("DOMContentLoaded", function() {
setTimeout(function() {
try {
// Detect user's browser language
var userLang = navigator.language || navigator.userLanguage;
userLang = userLang.split('-')[0]; // Extract the primary language code (e.g., "fr", "en")
// Multilingual FAQ database
var faqEntries = {
"fr": [
{
question: "question 1 FR",
answer: "answer 1 FR"
},
{
question: "question 2 FR",
answer: "answer 2 FR"
}
],
"en": [
{
question: "question 1 EN",
answer: "answer 1 EN"
},
{
question: "question 2 EN",
answer: "answer 2 EN"
}
]
};
// Select the FAQ based on detected language, default to English if not defined
var selectedFAQ = faqEntries[userLang] || faqEntries["en"];
// Generate JSON-LD schema
var faqData = {
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": selectedFAQ.map(entry => ({
"@type": "Question",
"name": entry.question,
"acceptedAnswer": {
"@type": "Answer",
"text": entry.answer
}
}))
};
// Create and insert the JSON-LD script
var scriptTag = document.createElement("script");
scriptTag.type = "application/ld+json";
scriptTag.textContent = JSON.stringify(faqData, null, 2);
document.head.appendChild(scriptTag);
} catch (error) {
console.error("Error generating FAQ schema:", error);
}
}, 1500);
});
</script>
{{blog_article_cta01}}
The script retrieves the user’s preferred language using navigator.language. Since some languages include a sub-code (fr-FR, en-US), we extract only the main part (fr, en).
Questions and answers are stored in a faqEntries object, where each language is represented by an array of objects containing the corresponding questions and answers.
The script checks whether the user’s language exists in faqEntries. If not, it defaults to the English version.
The script converts the selected FAQ into a JSON-LD object compliant with Schema.org recommendations, then dynamically injects it into the <head> section of the HTML document.
If your site supports multiple languages, you can expand the faqEntries object by adding entries for additional languages:
"es": [
{
"question": "question 1 ES",
"answer": "answer 1 ES"
},
{
"question": "question 2 ES",
"answer": "answer 2 ES"
}
]
You can tailor the questions and answers based on your industry. Ensure that responses are clear, precise, and optimized to match users’ search intent.
Once the script is integrated into your site, you can verify that Google correctly recognizes your markup using the Rich Results Test Tool:
🔗 https://search.google.com/test/rich-results
Implementing a multilingual FAQPage schema via JavaScript is an excellent solution for optimizing your international SEO and improving the user experience on your website. This script allows you to dynamically display the appropriate questions and answers based on the visitor’s language while adhering to Google’s best practices for structured data.
By adapting this method to your needs and regularly testing your schema, you will maximize your chances of achieving better rankings in search results and increasing user engagement on your site.