#All i18n fallbacks are not generated properly

6 messages · Page 1 of 1 (latest)

cinder ice
#

I have a project with config:

i18n: {
  locales: ['en', 'de', 'sv', 'fi', 'pl'],
  defaultLocale: 'en',
  routing: {
    prefixDefaultLocale: false,
    redirectToDefaultLocale: true,
    fallbackType: "rewrite",
  },
  fallback: {
    sv: 'en',
    fi: 'en',
    pl: 'en',
    de: 'en',
  },
},

Where all pages exist directly under pages/ and all translations are done by substituting strings, i.e. I want all pages to generate fallbacks for all locales other than en.

However, I do not get fallbacks for all pages. One of my pages is never generating fallbacks, and it perhaps seem like it is related to the page name. I have 4 pages under x/y/, and 3 of them work as expected, but the 4th one d.astro never results in a fallback. The same happens when I switch names on two pages, i.e. c.astro becomes d.astro and vice versa. So the page that worked before no longer works, i.e. it does not seem related to the content on the page.

I can add that this is only occurs during the build process. When I run the dev server, everything seem to be working as expected.

Where should I begin investigating this issue? I have not yet been able to generate a reproducible example. It works for most pages, but not for all pages under this particular map structure.

wide hullBOT
#

Hi @cinder ice. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the information in the knowledge sources, here are some steps and considerations for investigating your i18n fallback issue in Astro:

  1. Folder and File Naming Requirements
    Astro’s i18n routing relies on your file and folder structure matching the configuration in astro.config.mjs. The folder names for locales must match exactly the items in your locales array. However, since you are using prefixDefaultLocale: false, your default language (en) pages should be at the root of src/pages/, and other locales will be generated as fallbacks if configured properly. There is no explicit mention in the documentation of restrictions on file names like d.astro, but Astro’s file-based routing can sometimes have issues with certain file names or reserved words, especially single-letter or ambiguous names. Double-check that there are no naming conflicts or reserved words being used, and try renaming the file to see if the issue persists Configure i18n routing.

  2. Fallback Configuration
    Your fallback configuration appears correct. With fallbackType: "rewrite" and the fallback object mapping all non-en locales to en, Astro should generate fallback pages for all missing translations, rendering the English content at the requested locale URL without redirecting Fallbacki18n.routing.fallbackType.

#
  1. Build vs. Dev Differences
    The fact that the issue only occurs during the build process and not in dev suggests a possible bug or edge case in Astro’s static generation logic. The documentation does not provide details on known issues with specific file names, but it does recommend creating a minimal reproduction to help diagnose such problems Creating minimal reproductions.

  2. Next Steps for Investigation

    • Rename the Problematic File: Try renaming d.astro to something else (e.g., page-d.astro) and see if the fallback is generated. If the problem moves with the file name, it may indicate a bug or reserved word issue.
    • Check for Conflicts: Ensure there are no other files or folders named d at the same or higher directory level that could be causing a routing conflict.
    • Minimal Reproduction: Create a minimal Astro project with just the problematic structure and config. This will help isolate whether the issue is with your project or a bug in Astro itself. If you can reproduce the issue, consider sharing it with the Astro team for further investigation Creating minimal reproductions.
  3. Astro Error Reporting
    If a locale or path does not exist in your configured i18n.locales, Astro will throw a "MissingLocale" error, but your config seems correct in this regard The provided locale does not exist.

#

Summary:
There is no explicit documentation about issues with specific file names like d.astro, but your experience suggests a possible edge case or bug. Focus on file naming, check for conflicts, and create a minimal reproduction to help diagnose the issue. If the problem persists, report it to the Astro team with your minimal example.

If you need further help, providing a minimal reproduction is the best next step, as recommended in the troubleshooting guide.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@cinder ice Kapa.ai is still learning and improving, please let me know how I did by reacting below.