Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i18n fallback in SSG mode does not generate pages #10957

Open
1 task
adamkoch opened this issue May 6, 2024 · 2 comments
Open
1 task

i18n fallback in SSG mode does not generate pages #10957

adamkoch opened this issue May 6, 2024 · 2 comments
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority) feat: i18n Related to internalization

Comments

@adamkoch
Copy link

adamkoch commented May 6, 2024

Astro Info

My machine:
Astro                    v4.7.0
Node                     v18.18.2
System                   macOS (arm64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             @astrojs/tailwind
                         @astrojs/mdx
                         @astrojs/sitemap
                         @astrojs/react
                         astro-icon


Stackblitz machine:
Astro                    v4.7.1
Node                     v18.18.0
System                   Linux (x64)
Package Manager          unknown
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

This may just be me misunderstanding how i18n fallback works in SSG mode, but when i18n fallback is configured, no fallback is created automatically.

With the example in the docs:

export default defineConfig({
  i18n: {
    defaultLocale: "en",
    locales: ["es", "en", "fr"],
    fallback: {
      fr: "es"
    }
  }
})

The docs say:

Astro will ensure that a page is built in src/pages/fr for every page that exists in src/pages/es/. If the page does not already exist, then a page with a redirect to the corresponding es route will be created.

When testing this and going to /fr where there is no page /fr/index.astro, it shows shows a 404.

I asked kapa.ai in the discord and it seemed to agree it should be created without needing to set up dynamic routes for locale along with getStaticPaths().

What's the expected result?

Loading localhost/fr should render the /pages/index.astro file with currentLocale set to fr (even when no /pages/fr/index.astro exists).

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-qffjm2

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label May 6, 2024
@ematipico ematipico added - P4: important Violate documented behavior or significantly impacts performance (priority) feat: i18n Related to internalization and removed needs triage Issue needs to be triaged labels May 6, 2024
@ematipico
Copy link
Member

ematipico commented May 6, 2024

I can see the bug, but your expectations isn't correct:

Loading localhost/fr should render the /pages/index.astro file with currentLocale set to fr (even when no /pages/fr/index.astro exists).

localhost/fr will redirect to localhost. There's no rendering here. The docs are explicit about it:

you can redirect a user from one locale to another on a per-language basis.

Also, your example isn't correct. Can you fix it? You created an en/ folder but didn't set prefixDefaultLocale: true.

@adamkoch
Copy link
Author

adamkoch commented May 6, 2024

localhost/fr will redirect to localhost. There's no rendering here. The docs are explicit about it:

Fair enough but a redirect also doesn't seem to be working. The docs do say:

Astro will ensure that a page is built in src/pages/fr for every page that exists in src/pages/es/.

But I guess what you're saying is the page is built but all it has in it is a redirect to the fallback? I guess a feature request would be to be able to configure that behavior (perhaps possible with manual mode).

What I don't understand then, is if I have translated pages for all my site, but a single page not translated, and a user gets redirected to another locale as a fallback. Won't Astro then set currentLocale to the fallback locale, and therefore all future links from that page will also be the fallback locale? It seems like a better set up would be to render the fallback locale but with currentLocale still set to the original locale, but with some other property set which indicates it's a fallback page (so a banner or message can be displayed).

Also, your example isn't correct. Can you fix it? You created an en/ folder but didn't set prefixDefaultLocale: true.

Apologies, updated, I deleted the en/ folder as for my set up I had prefixDefaultLocale: false.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority) feat: i18n Related to internalization
Projects
None yet
Development

No branches or pull requests

2 participants