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'.
This commit is contained in:
+13
-1
@@ -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', 'uk', 'zh'],
|
||||
defaultLocale: 'en',
|
||||
localePrefix: 'never'
|
||||
localePrefix
|
||||
});
|
||||
|
||||
export const locales = routing.locales;
|
||||
|
||||
Reference in New Issue
Block a user