From 0beb74195e216f30685998a9b715895aabc41891 Mon Sep 17 00:00:00 2001 From: Michael Brusegard <56915010+michaelbrusegard@users.noreply.github.com> Date: Sun, 25 Aug 2024 13:19:08 +0200 Subject: [PATCH] feat: reorganise locale files --- next.config.js | 2 +- src/app/[locale]/(default)/news/(header)/layout.tsx | 2 +- src/app/[locale]/layout.tsx | 2 +- src/app/not-found.tsx | 2 +- src/components/layout/Footer.tsx | 2 +- src/components/layout/LogoLink.tsx | 2 +- src/components/layout/Nav.tsx | 2 +- src/components/news/ArticleCard.tsx | 2 +- src/components/news/ArticleItem.tsx | 2 +- src/components/settings/LocaleMenu.tsx | 4 ++-- src/lib/{ => locale}/config.ts | 2 +- src/{ => lib/locale}/i18n.ts | 3 ++- src/lib/{ => locale}/navigation.ts | 2 +- src/middleware.ts | 7 ++++++- 14 files changed, 21 insertions(+), 15 deletions(-) rename src/lib/{ => locale}/config.ts (93%) rename src/{ => lib/locale}/i18n.ts (67%) rename src/lib/{ => locale}/navigation.ts (75%) diff --git a/next.config.js b/next.config.js index bb92a5b..26cdcc5 100644 --- a/next.config.js +++ b/next.config.js @@ -5,7 +5,7 @@ import nextIntl from 'next-intl/plugin'; * for Docker builds. */ await import('./src/env.js'); -const withNextIntl = nextIntl('./src/i18n.ts'); +const withNextIntl = nextIntl('./src/lib/locale/i18n.ts'); /** @type {import("next").NextConfig} */ const config = {}; diff --git a/src/app/[locale]/(default)/news/(header)/layout.tsx b/src/app/[locale]/(default)/news/(header)/layout.tsx index eca5470..3b11d0b 100644 --- a/src/app/[locale]/(default)/news/(header)/layout.tsx +++ b/src/app/[locale]/(default)/news/(header)/layout.tsx @@ -2,7 +2,7 @@ import { SquarePen } from 'lucide-react'; import { useTranslations } from 'next-intl'; import { unstable_setRequestLocale } from 'next-intl/server'; -import { Link } from '@/lib/navigation'; +import { Link } from '@/lib/locale/navigation'; import { Button } from '@/components/ui/Button'; diff --git a/src/app/[locale]/layout.tsx b/src/app/[locale]/layout.tsx index 24bfeeb..0cc4abc 100644 --- a/src/app/[locale]/layout.tsx +++ b/src/app/[locale]/layout.tsx @@ -2,7 +2,7 @@ import { getTranslations, unstable_setRequestLocale } from 'next-intl/server'; import { Inter, Montserrat } from 'next/font/google'; import { notFound } from 'next/navigation'; -import { locales } from '@/lib/config'; +import { locales } from '@/lib/locale/config'; import { cx } from '@/lib/utils'; import { RootProviders } from '@/components/providers/RootProviders'; diff --git a/src/app/not-found.tsx b/src/app/not-found.tsx index 9d1c1de..0175f74 100644 --- a/src/app/not-found.tsx +++ b/src/app/not-found.tsx @@ -2,7 +2,7 @@ import { redirect, usePathname } from 'next/navigation'; -import { defaultLocale } from '@/lib/config'; +import { defaultLocale } from '@/lib/locale/config'; export default function NotFound() { const pathname = usePathname(); diff --git a/src/components/layout/Footer.tsx b/src/components/layout/Footer.tsx index b2dd899..f506cef 100644 --- a/src/components/layout/Footer.tsx +++ b/src/components/layout/Footer.tsx @@ -2,7 +2,7 @@ import { Bug, Mail } from 'lucide-react'; import { useTranslations } from 'next-intl'; import ExternalLink from 'next/link'; -import { Link } from '@/lib/navigation'; +import { Link } from '@/lib/locale/navigation'; import { Facebook } from '@/components/assets/icons/Facebook'; import { Github } from '@/components/assets/icons/Github'; diff --git a/src/components/layout/LogoLink.tsx b/src/components/layout/LogoLink.tsx index 58c0c24..0448fd9 100644 --- a/src/components/layout/LogoLink.tsx +++ b/src/components/layout/LogoLink.tsx @@ -1,6 +1,6 @@ import { useTranslations } from 'next-intl'; -import { Link } from '@/lib/navigation'; +import { Link } from '@/lib/locale/navigation'; import { cx } from '@/lib/utils'; import { Logo } from '@/components/assets/Logo'; diff --git a/src/components/layout/Nav.tsx b/src/components/layout/Nav.tsx index 4654c96..568373b 100644 --- a/src/components/layout/Nav.tsx +++ b/src/components/layout/Nav.tsx @@ -1,4 +1,4 @@ -import { Link } from '@/lib/navigation'; +import { Link } from '@/lib/locale/navigation'; import { Button } from '@/components/ui/Button'; diff --git a/src/components/news/ArticleCard.tsx b/src/components/news/ArticleCard.tsx index f64ed5f..957b646 100644 --- a/src/components/news/ArticleCard.tsx +++ b/src/components/news/ArticleCard.tsx @@ -1,6 +1,6 @@ import Image from 'next/image'; -import { Link } from '@/lib/navigation'; +import { Link } from '@/lib/locale/navigation'; import { cx } from '@/lib/utils'; import { InternalBadge } from '@/components/news/InternalBadge'; diff --git a/src/components/news/ArticleItem.tsx b/src/components/news/ArticleItem.tsx index a18ea51..314fcdc 100644 --- a/src/components/news/ArticleItem.tsx +++ b/src/components/news/ArticleItem.tsx @@ -1,6 +1,6 @@ import Image from 'next/image'; -import { Link } from '@/lib/navigation'; +import { Link } from '@/lib/locale/navigation'; import { cx } from '@/lib/utils'; import { InternalBadge } from '@/components/news/InternalBadge'; diff --git a/src/components/settings/LocaleMenu.tsx b/src/components/settings/LocaleMenu.tsx index 5ff377e..a793b6f 100644 --- a/src/components/settings/LocaleMenu.tsx +++ b/src/components/settings/LocaleMenu.tsx @@ -4,8 +4,8 @@ import { Globe2 } from 'lucide-react'; import { useParams } from 'next/navigation'; import * as React from 'react'; -import { flagIcons, locales } from '@/lib/config'; -import { usePathname, useRouter } from '@/lib/navigation'; +import { flagIcons, locales } from '@/lib/locale/config'; +import { usePathname, useRouter } from '@/lib/locale/navigation'; import { Button } from '@/components/ui/Button'; import { diff --git a/src/lib/config.ts b/src/lib/locale/config.ts similarity index 93% rename from src/lib/config.ts rename to src/lib/locale/config.ts index b839efa..e2338de 100644 --- a/src/lib/config.ts +++ b/src/lib/locale/config.ts @@ -1,6 +1,6 @@ import GBflagIcon from 'country-flag-icons/react/1x1/GB'; import NOflagIcon from 'country-flag-icons/react/1x1/NO'; -import type { Pathnames } from 'next-intl/navigation'; +import type { Pathnames } from 'next-intl/routing'; const flagIcons = { en: GBflagIcon, no: NOflagIcon }; diff --git a/src/i18n.ts b/src/lib/locale/i18n.ts similarity index 67% rename from src/i18n.ts rename to src/lib/locale/i18n.ts index 1fc89f6..4ee897b 100644 --- a/src/i18n.ts +++ b/src/lib/locale/i18n.ts @@ -2,5 +2,6 @@ import { getRequestConfig } from 'next-intl/server'; export default getRequestConfig(async ({ locale }) => ({ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - messages: (await import(`../messages/${locale}.json`)).default as Messages, + messages: (await import(`../../../messages/${locale}.json`)) + .default as Messages, })); diff --git a/src/lib/navigation.ts b/src/lib/locale/navigation.ts similarity index 75% rename from src/lib/navigation.ts rename to src/lib/locale/navigation.ts index 0c676df..4b15167 100644 --- a/src/lib/navigation.ts +++ b/src/lib/locale/navigation.ts @@ -1,6 +1,6 @@ import { createLocalizedPathnamesNavigation } from 'next-intl/navigation'; -import { localePrefix, locales, pathnames } from '@/lib/config'; +import { localePrefix, locales, pathnames } from '@/lib/locale/config'; export const { Link, redirect, usePathname, useRouter, getPathname } = createLocalizedPathnamesNavigation({ locales, localePrefix, pathnames }); diff --git a/src/middleware.ts b/src/middleware.ts index 82d9d62..6ccec91 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -1,6 +1,11 @@ import createMiddleware from 'next-intl/middleware'; -import { defaultLocale, localePrefix, locales, pathnames } from '@/lib/config'; +import { + defaultLocale, + localePrefix, + locales, + pathnames, +} from '@/lib/locale/config'; export default createMiddleware({ defaultLocale,