mirror of
https://github.com/logos-co/logos-web.git
synced 2026-08-27 12:11:14 +00:00
feat: enhance i18n configuration with locale handling and middleware integration
This commit is contained in:
@@ -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,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -6,6 +6,6 @@ export const routing = defineRouting({
|
||||
|
||||
// Used when no locale matches
|
||||
defaultLocale: 'en',
|
||||
localePrefix: 'always',
|
||||
localePrefix: 'as-needed',
|
||||
localeDetection: false,
|
||||
})
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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|.*\\..*).*)',
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"buildCommand": "pnpm --filter web build",
|
||||
"outputDirectory": "apps/web/out"
|
||||
}
|
||||
Reference in New Issue
Block a user