Update lang attribute on locale change

This commit is contained in:
WalkingPizza 2022-09-02 14:46:31 +02:00
parent 2c43eb4e39
commit 55efd7b034
2 changed files with 5 additions and 0 deletions

View File

@ -22,6 +22,7 @@ import {
} from './exposedHooks';
import injectionZones from './injectionZones';
import favicon from './favicon.ico';
import localStorageKey from './components/LanguageProvider/utils/localStorageKey';
class StrapiApp {
constructor({ adminConfig, appPlugins, library, middlewares, reducers }) {
@ -425,6 +426,8 @@ class StrapiApp {
fields: { fields },
} = this.library;
console.log({ settings: this.settings });
return (
<Providers
authLogo={this.configurations.authLogo}
@ -457,6 +460,7 @@ class StrapiApp {
href: this.configurations.head.favicon,
},
]}
htmlAttributes={{ lang: localStorage.getItem(localStorageKey) || 'en' }}
/>
<BrowserRouter basename={basename}>
<App store={store} />

View File

@ -21,6 +21,7 @@ const LanguageProvider = ({ children, localeNames, messages }) => {
useEffect(() => {
// Set user language in local storage.
window.localStorage.setItem(localStorageKey, locale);
document.documentElement.setAttribute('lang', locale);
}, [locale]);
const changeLocale = (locale) => {