From 78a9512e0dd55ae9bcfc81eff30657df0d2f1653 Mon Sep 17 00:00:00 2001 From: shuki Date: Sun, 12 Apr 2026 03:43:19 +0300 Subject: [PATCH] feat: configurable localePrefix via NEXT_PUBLIC_LOCALE_PREFIX Allow the next-intl localePrefix mode to be set via environment variable at build time, defaulting to the existing 'never' behavior. This is useful when proxying Bulwark under a sub-path (where 'never' can trigger rewrite loops) or when users prefer URL-embedded locales (/en/settings vs /settings). Usage: NEXT_PUBLIC_LOCALE_PREFIX=always npm run build Accepted values: 'never' (default), 'always', 'as-needed'. --- i18n/routing.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/i18n/routing.ts b/i18n/routing.ts index e872638..372146e 100644 --- a/i18n/routing.ts +++ b/i18n/routing.ts @@ -1,9 +1,21 @@ import { defineRouting } from 'next-intl/routing'; +// Locale prefix mode can be configured via NEXT_PUBLIC_LOCALE_PREFIX. +// - "never" (default): /settings — locale from cookie/Accept-Language +// - "always": /en/settings — locale always in the URL +// - "as-needed": /settings for default locale, /fr/settings otherwise +// When proxying Bulwark under a sub-path (NEXT_PUBLIC_BASE_PATH), "always" is +// recommended to avoid next-intl rewrite loops caused by locale detection +// conflicting with the proxy's path rewriting. +const localePrefix = (process.env.NEXT_PUBLIC_LOCALE_PREFIX ?? 'never') as + | 'never' + | 'always' + | 'as-needed'; + export const routing = defineRouting({ locales: ['en', 'fr', 'de', 'es', 'it', 'ja', 'ko', 'lv', 'nl', 'pl', 'pt', 'ru', 'zh'], defaultLocale: 'en', - localePrefix: 'never' + localePrefix }); export const locales = routing.locales;