Skip to content

feat: configurable localePrefix via NEXT_PUBLIC_LOCALE_PREFIX#182

Open
shukiv wants to merge 1 commit intobulwarkmail:mainfrom
shukiv:feat-configurable-locale-prefix
Open

feat: configurable localePrefix via NEXT_PUBLIC_LOCALE_PREFIX#182
shukiv wants to merge 1 commit intobulwarkmail:mainfrom
shukiv:feat-configurable-locale-prefix

Conversation

@shukiv
Copy link
Copy Markdown

@shukiv shukiv commented Apr 12, 2026

Summary

Allow the next-intl localePrefix mode to be configured via the NEXT_PUBLIC_LOCALE_PREFIX env var at build time. Default behavior ('never') is unchanged.

Motivation

Two use cases where the hardcoded 'never' mode is problematic:

  1. Proxied under a sub-path. When Bulwark is reverse-proxied under a path prefix (e.g. /webmail), localePrefix: 'never' can trigger next-intl rewrite loops because locale detection conflicts with the proxy's path handling. Switching to 'always' resolves this by making the locale explicit in URLs.

  2. Operator preference. Some deployments prefer URL-embedded locales (/en/settings) over cookie-driven detection (/settings) for link shareability, analytics, and caching.

Changes

  • i18n/routing.ts: read localePrefix from process.env.NEXT_PUBLIC_LOCALE_PREFIX with 'never' as default; accept the three standard next-intl values ('never' | 'always' | 'as-needed')

Usage

NEXT_PUBLIC_LOCALE_PREFIX=always npm run build

When unset, the existing behavior ('never') is preserved — no breaking change for existing deployments.

Test plan

  • Reviewer: build with NEXT_PUBLIC_LOCALE_PREFIX=never (default) — verify URLs like /settings work
  • Reviewer: build with NEXT_PUBLIC_LOCALE_PREFIX=always — verify URLs like /en/settings work and locale switcher generates prefixed URLs

Notes

This pairs with #181 (configurable basePath) for deployments proxying under a sub-path.

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'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant