🎙️ a11y: update html lang attribute (#3636)

* refactor: remove duplicate localStorage lang call

* refactor: use cookies to handle langcode

* feat: override index.html lang w/ cookie pref

* refactor: only read index on server start

* refactor: rename lang cookie & localstorage as backup

* refactor: use atomWithLocalStorage in language store

* fix: forced reflow warning in language select
This commit is contained in:
Jacob Colyvan 2024-08-30 20:57:29 +10:00 committed by GitHub
parent a0042317b2
commit 2ce4f66218
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 71 additions and 19 deletions

View file

@ -1,10 +1,11 @@
import { atom } from 'recoil';
import Cookies from 'js-cookie';
import { atomWithLocalStorage } from './utils';
const userLang = navigator.language || navigator.languages[0];
const defaultLang = () => {
const userLang = navigator.language || navigator.languages[0];
return Cookies.get('lang') || localStorage.getItem('lang') || userLang;
};
const lang = atom({
key: 'lang',
default: localStorage.getItem('lang') || userLang,
});
const lang = atomWithLocalStorage('lang', defaultLang());
export default { lang };