feat: enhance i18n configuration with locale handling and middleware integration

This commit is contained in:
jinhojang6
2026-04-24 03:03:27 +09:00
parent 9bd1a097fe
commit 4e45483061
5 changed files with 36 additions and 10 deletions
+20 -4
View File
@@ -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,
}
})
+1 -1
View File
@@ -6,6 +6,6 @@ export const routing = defineRouting({
// Used when no locale matches
defaultLocale: 'en',
localePrefix: 'always',
localePrefix: 'as-needed',
localeDetection: false,
})
+2 -1
View File
@@ -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,
+13
View File
@@ -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|.*\\..*).*)',
}
-4
View File
@@ -1,4 +0,0 @@
{
"buildCommand": "pnpm --filter web build",
"outputDirectory": "apps/web/out"
}