diff --git a/adapter/src/utils/useLocale.js b/adapter/src/utils/useLocale.js index ce7cc09d..e0672d48 100644 --- a/adapter/src/utils/useLocale.js +++ b/adapter/src/utils/useLocale.js @@ -27,6 +27,7 @@ export const useLocale = ({ userSettings, configDirection }) => { // Intl.Locale dir utils aren't supported in firefox, so use i18n const localeDirection = i18n.dir(locale.language) setDocumentDirection({ localeDirection, configDirection }) + document.documentElement.setAttribute('lang', locale.baseName) setResult({ locale, direction: localeDirection }) }, [userSettings, configDirection]) diff --git a/adapter/src/utils/useLocale.test.js b/adapter/src/utils/useLocale.test.js index de387b98..00be9ca0 100644 --- a/adapter/src/utils/useLocale.test.js +++ b/adapter/src/utils/useLocale.test.js @@ -301,3 +301,20 @@ describe('config direction is respected for the document direction', () => { ) }) }) + +test('document `lang` attribute is set', () => { + jest.spyOn(document.documentElement, 'setAttribute') + const userSettings = { keyUiLocale: 'pt-BR' } + + renderHook(() => + useLocale({ + userSettings, + configDirection: undefined, + }) + ) + + expect(document.documentElement.setAttribute).toHaveBeenCalledWith( + 'lang', + 'pt-BR' + ) +})