Skip to content

i18n fallback pages are not generated at build when page filename starts with locale key #14359

@fredriknorlin

Description

@fredriknorlin

Astro Info

Astro                    v5.13.7
Node                     v22.15.1
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?

No response

Describe the Bug

When using Astro i18n fallbacks with fallbackType: 'rewrite', builds do not generate fallback files for pages whose filenames begin with a locale key (e.g., svalbard.astro, denmark.astro, etc.).

(This only affects astro build, astro dev works as expected.)

Config:

// @ts-check
import { defineConfig } from 'astro/config';

// https://astro.build/config
export default defineConfig({
  i18n: {
    locales: ['en', 'de', 'sv'],
    defaultLocale: 'en',
    routing: {
      fallbackType: 'rewrite',
    },
    fallback: {
      sv: 'en',
      de: 'en',
    },
  },
});

Page structure:

src/
└── pages/
    ├── denmark.astro
    ├── index.astro
    ├── norway.astro
    └── svalbard.astro

Output from astro build:

(Notice how astro do not produce fallback files for pages whose name with a locale key (denmark/svalbard), while it works for the rest of the pages (index/norway))

12:37:30 ▶ src/pages/denmark.astro
12:37:30   └─ /denmark/index.html (+20ms) 
12:37:30 ▶ src/pages/norway.astro
12:37:30   └─ /norway/index.html (+5ms) 
12:37:30 ▶ src/pages/norway.astro
12:37:30   └─ /sv/norway/index.html (+11ms) 
12:37:30 ▶ src/pages/norway.astro
12:37:30   └─ /de/norway/index.html (+5ms) 
12:37:30 ▶ src/pages/svalbard.astro
12:37:30   └─ /svalbard/index.html (+4ms) 
12:37:30 ▶ src/pages/index.astro
12:37:30   └─ /index.html (+6ms) 
12:37:30 ▶ src/pages/index.astro
12:37:30   └─ /sv/index.html (+6ms) 
12:37:30 ▶ src/pages/index.astro
12:37:30   └─ /de/index.html (+5ms) 

You can run astro build in https://stackblitz.com/edit/github-cferehre-wbcz1knm?file=astro.config.mjs to see this exact problem.

What's the expected result?

I expect Astro to generate fallback files for all pages:

12:37:30 ▶ src/pages/denmark.astro
12:37:30   └─ /denmark/index.html (+20ms) 
12:37:30 ▶ src/pages/denmark.astro
12:37:30   └─ /sv/denmark/index.html (+11ms) 
12:37:30 ▶ src/pages/denmark.astro
12:37:30   └─ /de/denmark/index.html (+5ms) 
12:37:30 ▶ src/pages/norway.astro
12:37:30   └─ /norway/index.html (+5ms) 
12:37:30 ▶ src/pages/norway.astro
12:37:30   └─ /sv/norway/index.html (+11ms) 
12:37:30 ▶ src/pages/norway.astro
12:37:30   └─ /de/norway/index.html (+5ms) 
12:37:30 ▶ src/pages/svalbard.astro
12:37:30   └─ /svalbard/index.html (+4ms) 
12:37:30 ▶ src/pages/svalbard.astro
12:37:30   └─ /sv/svalbard/index.html (+11ms) 
12:37:30 ▶ src/pages/svalbard.astro
12:37:30   └─ /de/svalbard/index.html (+5ms) 
12:37:30 ▶ src/pages/index.astro
12:37:30   └─ /index.html (+6ms) 
12:37:30 ▶ src/pages/index.astro
12:37:30   └─ /sv/index.html (+6ms) 
12:37:30 ▶ src/pages/index.astro
12:37:30   └─ /de/index.html (+5ms) 

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-cferehre-wbcz1knm?file=astro.config.mjs

Participation

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P3: minor bugAn edge case that only affects very specific usage (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