Reputation: 430
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
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
Reputation: 430
I solved this question.
I added this in my App.js file:
document.documentElement.lang = i18n.language;
Upvotes: 15