From 87f456445c3992efc7abed890a2ad9f76d31f9a9 Mon Sep 17 00:00:00 2001 From: Mathias Oterhals Myklebust <24361490+mathiazom@users.noreply.github.com> Date: Mon, 7 Oct 2024 07:21:57 +0000 Subject: [PATCH] v3 - language switcher and translated legal links (#719) * feat(i18n): language switcher + translated legal links * refactor(queries): deduplicate DEFAULT_LANGUAGE_QUERY * fix(siteSettings): inline document id in groq query attempt to fix following error at build: > The error was caused by importing 'sanity/lib/index.mjs' in './studio/schemas/documents/siteSettings/brandAssets.ts'. * feat(LanguageSwitcher): include current language --- src/app/(main)/{ => [lang]}/layout.module.css | 0 src/app/(main)/{ => [lang]}/layout.tsx | 8 +- src/app/(main)/[lang]/page.tsx | 6 +- .../languageSwitcher/LanguageSwitcher.tsx | 52 +++++++++ .../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/middlewares/languageMiddleware.ts | 2 +- src/utils/get.tsx | 2 +- src/utils/hooks/useLanguage.ts | 107 ++++++++++++++++++ studio/lib/interfaces/legalDocuments.ts | 1 + studio/lib/interfaces/navigation.ts | 1 + studio/lib/interfaces/slugTranslations.ts | 10 +- studio/lib/queries/languages.ts | 5 - studio/lib/queries/siteSettings.ts | 5 +- 17 files changed, 225 insertions(+), 22 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 delete mode 100644 studio/lib/queries/languages.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} /> ) : (