Skip to content

Commit

Permalink
feat: reorganise locale files
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbrusegard committed Aug 25, 2024
1 parent 44a4d14 commit 0beb741
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down
2 changes: 1 addition & 1 deletion src/app/[locale]/(default)/news/(header)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion src/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/app/not-found.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/components/layout/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/components/layout/LogoLink.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/components/layout/Nav.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link } from '@/lib/navigation';
import { Link } from '@/lib/locale/navigation';

import { Button } from '@/components/ui/Button';

Expand Down
2 changes: 1 addition & 1 deletion src/components/news/ArticleCard.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/components/news/ArticleItem.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
4 changes: 2 additions & 2 deletions src/components/settings/LocaleMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/config.ts → src/lib/locale/config.ts
Original file line number Diff line number Diff line change
@@ -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 };

Expand Down
3 changes: 2 additions & 1 deletion src/i18n.ts → src/lib/locale/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}));
2 changes: 1 addition & 1 deletion src/lib/navigation.ts → src/lib/locale/navigation.ts
Original file line number Diff line number Diff line change
@@ -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 });
7 changes: 6 additions & 1 deletion src/middleware.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit 0beb741

Please sign in to comment.