feat(i18n): add locale-based routing setup

Add next-intl routing config, proxy middleware, and update request config to use requestLocale from middleware. Add @/i18n/* path alias to tsconfig.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
nxtkofi 2026-04-21 20:53:09 +02:00
parent c14d2d6f26
commit c4a35e97c3
4 changed files with 26 additions and 10 deletions

View file

@ -1,14 +1,12 @@
import { getRequestConfig } from "next-intl/server"; import { getRequestConfig } from 'next-intl/server';
import { headers } from "next/headers"; import { hasLocale } from 'next-intl';
import { routing } from './routing';
export default getRequestConfig(async () => { export default getRequestConfig(async ({ requestLocale }) => {
const headersList = await headers(); const requested = await requestLocale;
const acceptLanguage = headersList.get("accept-language"); const locale = hasLocale(routing.locales, requested)
? requested
const browserLocale = acceptLanguage?.split(",")[0]?.split("-")[0]; : routing.defaultLocale;
const supportedLocales = ["en", "pl"];
const locale = browserLocale && supportedLocales.includes(browserLocale) ? browserLocale : "en";
return { return {
locale, locale,

7
src/i18n/routing.ts Normal file
View file

@ -0,0 +1,7 @@
import { defineRouting } from 'next-intl/routing';
export const routing = defineRouting({
locales: ['en', 'pl'],
defaultLocale: 'en',
localePrefix: 'as-needed',
});

10
src/proxy.ts Normal file
View file

@ -0,0 +1,10 @@
import createMiddleware from 'next-intl/middleware';
import { routing } from './i18n/routing';
export default createMiddleware(routing);
export const config = {
matcher: [
'/((?!api|_next|_vercel|.*\\..*).*)',
],
};

View file

@ -24,6 +24,7 @@
"@/lib/*": ["./src/lib/*"], "@/lib/*": ["./src/lib/*"],
"@/hooks/*": ["./src/hooks/*"], "@/hooks/*": ["./src/hooks/*"],
"@/app/*": ["./src/app/*"], "@/app/*": ["./src/app/*"],
"@/i18n/*": ["./src/i18n/*"],
"@/constants": ["./src/constants.ts"] "@/constants": ["./src/constants.ts"]
} }
}, },