From aa8c0b657d6d274311f70196fe5c2dd5c634f92f Mon Sep 17 00:00:00 2001 From: Mathias Oterhals Myklebust Date: Fri, 27 Sep 2024 14:11:33 +0200 Subject: [PATCH 1/4] feat(i18n): language switcher + translated legal links --- src/app/(main)/{ => [lang]}/layout.module.css | 0 src/app/(main)/{ => [lang]}/layout.tsx | 8 +- .../languageSwitcher/LanguageSwitcher.tsx | 32 +++++ .../languageSwitcher.module.css | 11 ++ src/components/navigation/footer/Footer.tsx | 3 +- .../navigation/footer/FooterPreview.tsx | 21 +++- src/components/navigation/header/Header.tsx | 5 + .../navigation/header/header.module.css | 8 ++ src/utils/get.tsx | 2 +- src/utils/hooks/useLanguage.ts | 110 ++++++++++++++++++ studio/lib/interfaces/legalDocuments.ts | 1 + studio/lib/interfaces/navigation.ts | 1 + studio/lib/interfaces/slugTranslations.ts | 10 +- 13 files changed, 201 insertions(+), 11 deletions(-) rename src/app/(main)/{ => [lang]}/layout.module.css (100%) rename src/app/(main)/{ => [lang]}/layout.tsx (95%) create mode 100644 src/components/languageSwitcher/LanguageSwitcher.tsx create mode 100644 src/components/languageSwitcher/languageSwitcher.module.css create mode 100644 src/utils/hooks/useLanguage.ts diff --git a/src/app/(main)/layout.module.css b/src/app/(main)/[lang]/layout.module.css similarity index 100% rename from src/app/(main)/layout.module.css rename to src/app/(main)/[lang]/layout.module.css diff --git a/src/app/(main)/layout.tsx b/src/app/(main)/[lang]/layout.tsx similarity index 95% rename from src/app/(main)/layout.tsx rename to src/app/(main)/[lang]/layout.tsx index 1e54246fe..c33decf46 100644 --- a/src/app/(main)/layout.tsx +++ b/src/app/(main)/[lang]/layout.tsx @@ -26,8 +26,12 @@ const hasValidData = (data: unknown) => data && Object.keys(data).length > 0; export default async function Layout({ children, + params, }: Readonly<{ children: React.ReactNode; + params: { + lang: string; + }; }>) { const { perspective, isDraftMode } = getDraftModeInfo(); @@ -47,7 +51,7 @@ export default async function Layout({ ), loadStudioQuery( LEGAL_DOCUMENTS_BY_LANG_QUERY, - { language: "en" }, //TODO: replace this with selected language for the page + { language: params.lang }, { perspective }, ), loadStudioQuery(BRAND_ASSETS_QUERY, {}, { perspective }), @@ -90,6 +94,8 @@ export default async function Layout({ initialCompanyInfo={initialCompanyInfo} initialBrandAssets={initialBrandAssets} initialSoMe={initialSoMe} + initialLegal={initialLegal} + language={params.lang} /> ) : (