From b7db9c5fad19ee25ebaab8f49fe2353f865b51e0 Mon Sep 17 00:00:00 2001 From: "saito.k" Date: Mon, 19 Feb 2024 01:49:23 +0000 Subject: [PATCH] =?UTF-8?q?Merged=20PR=20752:=20[FB=E5=AF=BE=E5=BF=9C]Edge?= =?UTF-8?q?=E3=81=A7=E8=A1=A8=E7=A4=BA=E8=A8=80=E8=AA=9E=E3=81=8C=E5=88=87?= =?UTF-8?q?=E3=82=8A=E6=9B=BF=E3=82=8F=E3=82=89=E3=81=AA=E3=81=84=E3=81=93?= =?UTF-8?q?=E3=81=A8=E3=81=8C=E3=81=82=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task3728: 原因調査&調査結果をPBIに記載する](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3728) - cookieから言語情報取得時にほかのcookieが存在していると、うまく取得できなくなってしまう - https://into-the-program.com/javascript-cant-get-value-cookie-name-array/ - この方法でほかのcookieがある場合でも半角スペースを排除して正しく取得できるようにした。 ## レビューポイント - 特になし ## 動作確認状況 - ローカルで確認 ## 補足 - 相談、参考資料などがあれば --- dictation_client/src/App.tsx | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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]);