Skip to content

Commit

Permalink
perf(frontend)!: Update to next-intl v4
Browse files Browse the repository at this point in the history
  • Loading branch information
aXenDeveloper committed Dec 23, 2024
1 parent 4a56616 commit ecdbe73
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 57 deletions.
6 changes: 4 additions & 2 deletions apps/frontend/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import type welcome from '@/plugins/welcome/langs/en.json';

type Messages = typeof core & typeof admin & typeof welcome;

declare global {
interface IntlMessages extends Messages {}
declare module 'next-intl' {
interface AppConfig {
Messages: Messages;
}
}
2 changes: 1 addition & 1 deletion apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"geist": "^1.3.1",
"lucide-react": "^0.468.0",
"next": "^15.1.2",
"next-intl": "^3.26.2",
"next-intl": "4.0.0-beta-ddd5ae5",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-hook-form": "^7.54.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const createPackagesJSON = async ({
geist: '^1.3.1',
'lucide-react': '^0.469.0',
next: '^15.1.2',
'next-intl': '^3.26.2',
'next-intl': '4.0.0-beta-ddd5ae5',
react: '^19.0.0',
'react-dom': '^19.0.0',
'react-hook-form': '^7.54.1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import type welcome from '@/plugins/welcome/langs/en.json';

type Messages = typeof core & typeof admin & typeof welcome;

declare global {
interface IntlMessages extends Messages {}
declare module 'next-intl' {
interface AppConfig {
Messages: Messages;
}
}
6 changes: 4 additions & 2 deletions packages/frontend/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import type welcome from '../../apps/frontend/src/plugins/welcome/langs/en.json'

type Messages = typeof core & typeof admin & typeof welcome;

declare global {
interface IntlMessages extends Messages {}
declare module 'next-intl' {
interface AppConfig {
Messages: Messages;
}
}
4 changes: 2 additions & 2 deletions packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"@hookform/resolvers": "^3.9.1",
"lucide-react": "*",
"next": "^15.1.2",
"next-intl": "^3.26.2",
"next-intl": "4.0.0-beta-ddd5ae5",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-hook-form": "^7.54.1",
Expand All @@ -119,7 +119,7 @@
"eslint-config-typescript-vitnode": "workspace:*",
"lucide-react": "^0.469.0",
"next": "^15.1.2",
"next-intl": "^3.26.3",
"next-intl": "4.0.0-beta-ddd5ae5",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-hook-form": "^7.54.2",
Expand Down
12 changes: 7 additions & 5 deletions packages/frontend/src/components/translations-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { NamespaceKeys, NestedKeyOf, NextIntlClientProvider } from 'next-intl';
import {
Messages,
NamespaceKeys,
NestedKeyOf,
NextIntlClientProvider,
} from 'next-intl';
import { getLocale, getMessages } from 'next-intl/server';
import 'server-only';

Expand Down Expand Up @@ -30,10 +35,7 @@ const pick = (obj: object, paths: string[]) => {
};

export async function TranslationsProvider<
NestedKey extends NamespaceKeys<
IntlMessages,
NestedKeyOf<IntlMessages>
> = never,
NestedKey extends NamespaceKeys<Messages, NestedKeyOf<Messages>> = never,
>({
children,
namespaces,
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const i18nConfigVitNode = async ({
}) => Promise<{ default: object }>;
requestLocale: Promise<string | undefined>;
}) => {
let locale = await requestLocale;
let defaultLocale = 'en';
let locale = (await requestLocale) ?? 'en';

if (!locale) {
locale = 'en';
Expand All @@ -28,7 +28,7 @@ export const i18nConfigVitNode = async ({
const defaultLanguage = data.languages.find(lang => lang.default);
defaultLocale = defaultLanguage?.code ?? 'en';
if (!data.languages.find(lang => lang.code === locale)) {
locale = defaultLanguage?.code;
locale = defaultLanguage?.code ?? defaultLocale;
}
} catch (_) {
// If the request fails, we will use the default plugins
Expand Down
3 changes: 1 addition & 2 deletions packages/frontend/src/navigation/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { createNavigation } from 'next-intl/navigation';
import { createNavigation, QueryParams } from 'next-intl/navigation';
import { getLocale } from 'next-intl/server';
import { RedirectType } from 'next/navigation';
import { QueryParams } from 'node_modules/next-intl/dist/types/src/navigation/shared/utils';
import React from 'react';

import { usePathname, useRouter } from './router';
Expand Down
63 changes: 25 additions & 38 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ecdbe73

Please sign in to comment.