Minimal reproduction for a bug in Astro's server-side i18n helper
computePreferredLocaleList (Astro.preferredLocaleList / the endpoint
context.preferredLocaleList).
When a locale is configured in object form ({ path, codes }),
preferredLocaleList matches the browser's Accept-Language code with an
exact, case-sensitive string comparison, while the sibling APIs
(preferredLocale, and the string-form locale path) normalize case and the
-/_ separator. So a locale configured as en-us is dropped when the
browser sends en-US.
// astro.config.mjs
i18n: {
defaultLocale: 'english',
locales: [{ path: 'english', codes: ['en-us'] }, 'fr'],
}pnpm install
pnpm dev
# in another terminal:
curl -H "Accept-Language: en-US" http://localhost:4321/pref.jsonThe two helpers disagree on the same request: preferredLocale resolves
en-us, but preferredLocaleList returns [].
Controls that behave correctly:
// curl -H "Accept-Language: en-us" (exact case) -> ["en-us"]
// curl -H "Accept-Language: FR" (string locale) -> ["fr"]packages/astro/src/i18n/utils.ts, in computePreferredLocaleList: the
string-locale branch uses normalizeTheLocale(...), but the object-form
branch compares code === browserLocale.locale directly. computePreferredLocale
(singular) already normalizes the object-form code, which is why the two APIs
disagree.