Skip to content

i18n: Astro.currentLocale is default locale during SSG on index pages generated with getStaticPaths and build.format: file #14228

@jonmichaeldarby

Description

@jonmichaeldarby

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

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P4: importantViolate documented behavior or significantly impacts performance (priority)feat: i18nRelated to internalization (scope)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions