2
6 Comments

How do you handle <html lang> for multilingual sites with dynamic JSON content?

I'm building a self-discovery RPG-style site that supports 31 languages.
All text is loaded dynamically via JSON based on user browser language.

However, I realized my <html lang="ja"> tag made Google and AI think my entire site was Japanese-only.

Switching to <html lang="en"> felt like the best compromise, since I can't represent 31 languages at once.

I’d love to hear from others — how do you approach this?

on June 11, 2025
  1. 1

    Hey River,
    In my nextjs project every page has a select language, that lets the user change the language of the website and then set a cookie to the browser containing the language he choosed right ?.

    Then, i am using i18n package, on layout file every time the page render i check the browser cookies to see if there is a language choosed, if it's not i use the default language which is english, if there is a language i use it in lang attribute.

    I hope it's help you and if you have any questions i'm here.

    1. 1

      Thanks, Ayoub!

      After switching to cookie-based language management, now each page correctly reflects html lang=xx, and the site is recognized as multilingual. Currently, I get the language from navigator.language on the first visit, and from the cookie on subsequent visits.

      Interestingly, at first, AI suggested using html lang=en as the best compromise—but when I brought up cookie handling, it immediately said, “Yes, that’s the right way. Let me explain why it’s superior,” as if it never made the previous suggestion 😅

      Anyway, thank you for sharing your method. It really helped!

      1. 1

        You're welcome, it was a pleasure for me to help you for sure.

        1. 1

          Thanks again!
          One more thing—I’ve currently removed "inLanguage" from my json-LD.
          Since my site uses cookies to dynamically set html lang=xx, I was unsure whether I should include "inLanguage" in the structured data.

          But I’ve read that static structured data is preferred by Google over dynamically generated ones.

          So my question is:
          Should I statically output "inLanguage" for each language version, even if the language is already specified in html lang and cookies? Or is it fine to omit it entirely?

          Would love your insights.

          1. 1

            As i mentioned before i'm using Next-intl, it creates a json file for every language, and when the html lang=xx change, it automatically change the website language, if this is not the answer you want, let's simplify the question.😅

            1. 1

              Hey! Just realized I hadn’t replied — sorry for the delay 😅
              The issue is already resolved on my side, but thank you so much for your insight! Always helpful 🙌

              I hadn’t heard of next-intl before, so I looked into it after reading your comment — really educational. Appreciate you pointing me in that direction! 🙏

Trending on Indie Hackers
I spent $0 on marketing and got 1,200 website visitors - Here's my exact playbook User Avatar 68 comments Veo 3.1 vs Sora 2: AI Video Generation in 2025 🎬🤖 User Avatar 30 comments I built eSIMKitStore — helping travelers stay online with instant QR-based eSIMs 🌍 User Avatar 21 comments 🚀 Get Your Brand Featured on FaceSeek User Avatar 20 comments Day 6 - Slow days as a solo founder User Avatar 16 comments From side script → early users → real feedback (update on my SaaS journey) User Avatar 11 comments