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

View File

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