#Astro i18n folder structure + sitemap not working: What am I missing?

3 messages · Page 1 of 1 (latest)

neon wave
#

Hey! I have a few questions about Astro’s i18n setup (based on the official guide).

The docs show a structure like this:

src/
└─ pages/
   ├─ about.astro
   ├─ index.astro
   ├─ es/
   │  ├─ about.astro
   │  └─ index.astro
   └─ pt-br/
      ├─ about.astro
      └─ index.astro
  1. Do I really need a folder for each language?

If I have 20 languages plus a default one, does that mean 20 folders?
And does this mean I have to duplicate every page for every locale?

  1. I tried using a dynamic [locale] folder instead:
src/
└─ pages/
   ├─ index.astro   # docs say this file is always required
   └─ [locale]/
      ├─ about.astro
      └─ index.astro

And here’s my astro.config.mjs:

site: 'https://mysite.com',
output: 'server',
i18n: {
  defaultLocale: 'en',
  locales: ['en', 'es', 'fr'],
  routing: {
    prefixDefaultLocale: true,
  },
},
integrations: [
  sitemap({
    i18n: {
      defaultLocale: 'en',
      locales: {
        en: 'en',
        es: 'es',
        fr: 'fr',
      },
    },
  }),
],

But on build I get:

[WARN] [@astrojs/sitemap] No pages found!
`sitemap-index.xml` not created.

It looks like the sitemap integration doesn’t detect the routes when using the [locale] folder. Is this expected, or am I missing something in the configuration?

Docs

Learn how to use Astro’s i18n routing features to localize your site’s pages.

vivid dagger
#

Do I really need a folder for each language?

No, this is only an example of how you can structure your pages.
And, as you discovered, you can use dynamic routes with or without spread.

I tried using a dynamic [locale] folder instead:

That's because you're using output: 'server', in your configuration. The sitemap integration doesn't work with on-demand rendering:

This integration cannot generate sitemap entries for dynamic routes in SSR mode.
see: https://docs.astro.build/en/guides/integrations-guide/sitemap/#why-astro-sitemap

I don't have a solution for on-demand rendering, but you could take a look at @inox-tools/sitemap-ext. I never tested it myself, but maybe this can work for your use case!