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

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

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

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.

Why use a multilingual FAQ schema?

Enhancing natural SEO

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.

Improving user experience

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.

Strengthening content relevance

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.

Implementing a multilingual FAQ schema with JavaScript

We will use JavaScript to:

  • Detect the user’s browser language.
  • Dynamically select the corresponding FAQ from multiple preconfigured versions.
  • Generate a JSON-LD markup following Google’s recommendations for structured data.
  • Inject this markup into the <head> section of the HTML document.

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}}

Detailed explanation of the code

1. Detecting the browser language

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).

2. Defining a multilingual FAQ database

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.

3. Automatically selecting the FAQ based on detected language

The script checks whether the user’s language exists in faqEntries. If not, it defaults to the English version.

4. Generating and inserting JSON-LD markup

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.

Customization and Aadaptation

Adding new languages

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" 
    }
]

Modifying questions and answers

You can tailor the questions and answers based on your industry. Ensure that responses are clear, precise, and optimized to match users’ search intent.

Testing schema validity

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

Conclusion

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.

Our cooking skills are questionable. Our web skills? Not at all. Let’s talk!
Unique & tailor-made website
Full control, zero dependency
Fast, smooth, SEO-optimized
Book a Meeting
bebranded realisations image
Take a look at some of our latest creations
Our Realisations
A multilingual FAQ schema enhances SEO by allowing search engines to understand and index content in multiple languages, improving visibility in international search results and increasing click-through rates (CTR).
The most effective method is to use navigator.language in JavaScript, which retrieves the user’s preferred language from their browser settings and dynamically displays the appropriate FAQ schema.
Yes, the JavaScript-based multilingual FAQ schema can be integrated into WordPress, Shopify, and other CMS platforms by adding the script to the site’s <head> section or using a custom script plugin.
You can test your schema using Google’s Rich Results Test Tool (https://search.google.com/test/rich-results) to ensure that the structured data is properly recognized and optimized for search engines.
none
none

Let's grow your website - and the rest

Our team is here to understand your needs & work with you to create your digital experience.