evgeniya.osmakova
evgeniya.osmakova

Reputation: 430

React, i18next and html attr lang

I use React+i18next and have two languages on my website.

How to make change HTML 'lang' attribute on my page?

I use i18next-browser-languagedetector but lang attr does not change

Upvotes: 11

Views: 4666

Answers (3)

Hayotillo
Hayotillo

Reputation: 1

document.querySelector('html').setAttribute('lang', 'en')

Upvotes: 0

Alex Court
Alex Court

Reputation: 178

If you're using your interface to allow a user to select/change the active language for i18n, then here is a way to add a callback to the i18n instance to keep the html lng tag in sync with i18n.

i18n.on('languageChanged', (lng) => (document.documentElement.lang = lng))

Upvotes: 10

evgeniya.osmakova
evgeniya.osmakova

Reputation: 430

I solved this question.

I added this in my App.js file:

document.documentElement.lang = i18n.language;

Upvotes: 15

Related Questions