Astro Info
Astro v5.12.9
Node v22.18.0
System macOS (arm64)
Package Manager npm
Output static
Adapter none
Integrations none
If this issue only occurs in one browser, which browser is a problem?
N/A
Describe the Bug
With the following values in astro.config.mjs:
build: {
format: 'file',
},
output: 'static',
trailingSlash: 'never',
and an i18n config that includes a defaultLocale and one or more additional locales:
i18n: {
defaultLocale: 'en-us',
locales: [
{
path: 'en-us',
codes: ['en-US'],
},
{
path: 'es-mx',
codes: ['es-MX'],
},
{
path: 'fr-fr',
codes: ['fr-FR'],
},
],
},
During SSG (astro build), getStaticPaths on an Astro page at the root/index of a route with a [locale] param (/pages/[locale].astro or /pages/[locale]/index.astro) makes the output of Astro.currentLocale fall back to the defaultLocale instead of the locale that matches the value of the locale param. On non-index routes (i.e. /[locale]/about.astro), Astro.currentLocale correctly outputs a locale that matches the value of the locale param.
For example, given the configuration above and /pages/[locale]/index.astro:
- locale
en-us will output en-us.html and Astro.currentLocale will be en-US
- locale
es-mx will output es-mx.html and Astro.currentLocale will be en-US
- locale
fr-fr will output fr-fr.html and Astro.currentLocale will be en-US
What's the expected result?
During SSG (astro build), getStaticPaths on an Astro page at the root/index of a route with a [locale] param (/pages/[locale].astro or /pages/[locale]/index.astro), Astro.currentLocale correctly outputs a locale that matches the value of the locale param.
For example, given the configuration above and /pages/[locale]/index.astro:
- locale
en-us will output en-us.html and Astro.currentLocale will be en-US
- locale
es-mx will output es-mx.html and Astro.currentLocale will be es-MX
- locale
fr-fr will output fr-fr.html and Astro.currentLocale will be fr-FR
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-kpnpjbu2?file=src%2Fpages%2Findex.astro
Participation
Astro Info
If this issue only occurs in one browser, which browser is a problem?
N/A
Describe the Bug
With the following values in
astro.config.mjs:and an
i18nconfig that includes adefaultLocaleand one or more additional locales:During SSG (
astro build),getStaticPathson an Astro page at the root/index of a route with a[locale]param (/pages/[locale].astroor/pages/[locale]/index.astro) makes the output ofAstro.currentLocalefall back to thedefaultLocaleinstead of the locale that matches the value of thelocaleparam. On non-index routes (i.e./[locale]/about.astro),Astro.currentLocalecorrectly outputs a locale that matches the value of thelocaleparam.For example, given the configuration above and
/pages/[locale]/index.astro:en-uswill outputen-us.htmlandAstro.currentLocalewill been-USes-mxwill outputes-mx.htmlandAstro.currentLocalewill been-USfr-frwill outputfr-fr.htmlandAstro.currentLocalewill been-USWhat's the expected result?
During SSG (
astro build),getStaticPathson an Astro page at the root/index of a route with a[locale]param (/pages/[locale].astroor/pages/[locale]/index.astro),Astro.currentLocalecorrectly outputs a locale that matches the value of thelocaleparam.For example, given the configuration above and
/pages/[locale]/index.astro:en-uswill outputen-us.htmlandAstro.currentLocalewill been-USes-mxwill outputes-mx.htmlandAstro.currentLocalewill bees-MXfr-frwill outputfr-fr.htmlandAstro.currentLocalewill befr-FRLink to Minimal Reproducible Example
https://stackblitz.com/edit/github-kpnpjbu2?file=src%2Fpages%2Findex.astro
Participation