diff --git a/frontend/src/i18n/index.ts b/frontend/src/i18n/index.ts index 54a6b70..765148b 100644 --- a/frontend/src/i18n/index.ts +++ b/frontend/src/i18n/index.ts @@ -20,6 +20,18 @@ function setup() { return _i18n; } +// Sets the active locale. +function setLocale(newLocale: any) { + _i18n.global.locale = newLocale; + setDocumentAttributesFor(newLocale); +} + +function setDocumentAttributesFor(locale: any) { + const htmlElement = document.querySelector("html"); + + htmlElement?.setAttribute("lang", locale); +} + // Public interface export default { // Expose the VueI18n instance via a getter @@ -27,4 +39,5 @@ export default { return _i18n; }, setup, + setLocale, };