mirror of
https://github.com/UiO-Gaming/name-100-uio-gamers.git
synced 2026-11-05 13:56:53 +01:00
Keep the html lang attribute in sync with the selected language
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b27be83297
commit
56d86d9ed2
1 file changed
+5
-1
@@ -1,5 +1,5 @@
|
||||
"use client";
|
||||
import React, { createContext, useContext, useSyncExternalStore } from "react";
|
||||
import React, { createContext, useContext, useEffect, useSyncExternalStore } from "react";
|
||||
|
||||
export type Language = "en" | "no";
|
||||
|
||||
@@ -29,6 +29,10 @@ const getServerSnapshot = (): Language => "en";
|
||||
export const LanguageProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||
const language = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
||||
|
||||
useEffect(() => {
|
||||
document.documentElement.lang = language;
|
||||
}, [language]);
|
||||
|
||||
const setLanguage = (lang: Language) => {
|
||||
localStorage.setItem("language", lang);
|
||||
listeners.forEach((listener) => listener());
|
||||
|
||||
Reference in new issue
Block a user