diff --git a/dictation_client/src/App.tsx b/dictation_client/src/App.tsx index 1d47893..f08dfd1 100644 --- a/dictation_client/src/App.tsx +++ b/dictation_client/src/App.tsx @@ -43,14 +43,18 @@ const App = (): JSX.Element => { // Language読み取り useLayoutEffect(() => { - const language = document.cookie - .trim() - .split(";") - .map((x) => x.split("=")) - .find((x) => x.length === 2 && x[0] === "language"); + const { cookie } = document; - if (language) { - i18n.changeLanguage(language[1]); + if (cookie) { + const cookieArray = cookie.split(";"); + const language = cookieArray.find((x) => + // 先頭の空白を削除してから判定 + x.trim().startsWith("language=") + ); + + if (language) { + i18n.changeLanguage(language.split("=")[1]); + } } }, [i18n]);