From 4e454830612464d7a76f1f9f04cff0b2d2af93c9 Mon Sep 17 00:00:00 2001 From: jinhojang6 Date: Fri, 24 Apr 2026 03:03:27 +0900 Subject: [PATCH] feat: enhance i18n configuration with locale handling and middleware integration --- apps/web/i18n/request.ts | 24 ++++++++++++++++++++---- apps/web/i18n/routing.ts | 2 +- apps/web/next.config.mjs | 3 ++- apps/web/proxy.ts | 13 +++++++++++++ vercel.json | 4 ---- 5 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 apps/web/proxy.ts delete mode 100644 vercel.json diff --git a/apps/web/i18n/request.ts b/apps/web/i18n/request.ts index 2d6c0fe8fc..c36c695e7d 100644 --- a/apps/web/i18n/request.ts +++ b/apps/web/i18n/request.ts @@ -1,11 +1,27 @@ import { getRequestConfig } from 'next-intl/server' +import { hasLocale } from 'next-intl' import { routing } from './routing' +const isProduction = process.env.NODE_ENV === 'production' + // docs: https://next-intl.dev/docs/getting-started/app-router/with-i18n-routing#i18n-request -export default getRequestConfig(async () => { +export default getRequestConfig(async ({ requestLocale }) => { + if (isProduction) { + return { + locale: routing.defaultLocale, + messages: (await import(`../messages/${routing.defaultLocale}.json`)) + .default, + } + } + + const requested = await requestLocale + const locale = + requested && hasLocale(routing.locales, requested) + ? requested + : routing.defaultLocale + return { - locale: routing.defaultLocale, - messages: (await import(`../messages/${routing.defaultLocale}.json`)) - .default, + locale, + messages: (await import(`../messages/${locale}.json`)).default, } }) diff --git a/apps/web/i18n/routing.ts b/apps/web/i18n/routing.ts index bff4a8a8ff..ca465afac3 100644 --- a/apps/web/i18n/routing.ts +++ b/apps/web/i18n/routing.ts @@ -6,6 +6,6 @@ export const routing = defineRouting({ // Used when no locale matches defaultLocale: 'en', - localePrefix: 'always', + localePrefix: 'as-needed', localeDetection: false, }) diff --git a/apps/web/next.config.mjs b/apps/web/next.config.mjs index 0089826ab6..463e2a2a26 100644 --- a/apps/web/next.config.mjs +++ b/apps/web/next.config.mjs @@ -4,13 +4,14 @@ import createNextIntlPlugin from 'next-intl/plugin' const withNextIntl = createNextIntlPlugin() const workspaceRoot = fileURLToPath(new URL('../..', import.meta.url)) +const isProduction = process.env.NODE_ENV === 'production' const nextConfig = { basePath: process.env.BASE_PATH || undefined, images: { unoptimized: true, }, - output: 'export', + ...(isProduction && { output: 'export' }), reactStrictMode: true, transpilePackages: ['@repo/ui'], trailingSlash: false, diff --git a/apps/web/proxy.ts b/apps/web/proxy.ts new file mode 100644 index 0000000000..fabef71b5e --- /dev/null +++ b/apps/web/proxy.ts @@ -0,0 +1,13 @@ +import createMiddleware from 'next-intl/middleware' + +import { routing } from './i18n/routing' + +const handleI18nRouting = createMiddleware(routing) + +export default function proxy(request: import('next/server').NextRequest) { + return handleI18nRouting(request) +} + +export const config = { + matcher: '/((?!api|_next|_vercel|.*\\..*).*)', +} diff --git a/vercel.json b/vercel.json deleted file mode 100644 index 44f0179fea..0000000000 --- a/vercel.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "buildCommand": "pnpm --filter web build", - "outputDirectory": "apps/web/out" -}