Skip to content

Commit

Permalink
Add a failsafe if the document language does not switch
Browse files Browse the repository at this point in the history
  • Loading branch information
nygrenh committed Sep 23, 2024
1 parent cd32f00 commit 3d27c7d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion services/course-material/src/components/layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
NavItem,
NavItems,
} from "@/shared-module/common/components/Navigation/NavBar"
import { getDir } from "@/shared-module/common/hooks/useLanguage"
import ietfLanguageTagToHumanReadableName from "@/shared-module/common/utils/ietfLanguageTagToHumanReadableName"
import withNoSsr from "@/shared-module/common/utils/withNoSsr"

Expand Down Expand Up @@ -86,9 +87,22 @@ const Layout: React.FC<React.PropsWithChildren<LayoutProps>> = ({ children }) =>
}, [changedLanguageUrl, router])

useEffect(() => {
if (currentLanguageCode && i18n.language !== currentLanguageCode) {
if (!currentLanguageCode) {
return
}
if (i18n.language !== currentLanguageCode) {
i18n.changeLanguage(currentLanguageCode)
}
const htmlElement = document.querySelector("html")
if (!htmlElement || !currentLanguageCode) {
return
}
setTimeout(() => {
// eslint-disable-next-line i18next/no-literal-string
htmlElement.setAttribute("lang", currentLanguageCode)
// eslint-disable-next-line i18next/no-literal-string
htmlElement.setAttribute("dir", getDir(currentLanguageCode))
}, 100)
}, [currentLanguageCode, i18n])

const layoutContextValue = useMemo(() => {
Expand Down

0 comments on commit 3d27c7d

Please sign in to comment.