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 dynamic routes: build log differs from build output #10621

Open
1 task
Because789 opened this issue Mar 31, 2024 · 2 comments
Open
1 task

i18n dynamic routes: build log differs from build output #10621

Because789 opened this issue Mar 31, 2024 · 2 comments
Labels
- P2: nice to have Not breaking anything but nice to have (priority)

Comments

@Because789
Copy link

Astro Info

Astro                    v4.5.12
Node                     v20.11.1
System                   Linux (x64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             @astrojs/mdx
                         @astrojs/tailwind
                         astro-icon

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

No response

Describe the Bug

I have the dynamic route src/pages/[...lang]/index.astro in my project (prefixDefaultLocale: false). It runs on dev server without any issues and builds correctly. But the build log shows that it generates the routes: /index.html, /en/index.html, /en/index.html and /en/en/index.html:

Screenshot (211)

What's the expected result?

Show correct build output in logs.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-quy3ic?file=src%2Fpages%2F%5B...lang%5D%2Findex.astro

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 Mar 31, 2024
@matthewp matthewp added - P2: nice to have Not breaking anything but nice to have (priority) and removed needs triage Issue needs to be triaged labels Apr 2, 2024
@1574242600
Copy link
Contributor

1574242600 commented Apr 15, 2024

Can you tell me why this is necessary?
which results in duplicate language prefix.

export function staticPathsLangParams() {
    const urls = getRelativeLocaleUrlList();
    return urls.map((url) => ({
        params: { lang: url === "/" ? undefined : url },
    }));
}

export const getStaticPaths = staticPathsLangParams;

As for not generating /en/en/index.html, it's because /en/index.html is considered the same path and is skipped.

// Do not render the fallback route if there is already a translated page
// with the same path
if (
route.type === 'fallback' &&
// If route is index page, continue rendering. The index page should
// always be rendered
route.pathname !== '/' &&
// Check if there is a translated page with the same path
Object.values(options.allPages).some((val) => pathname.match(val.route.pattern))
) {
return;
}

@ematipico
Copy link
Member

ematipico commented Apr 16, 2024

This use case seems to be a bit of a stretch to me.

This use case uses an API to retrieve all the configured locales and generate pages from it. However, the project is configured to not prefix the default locale. The use case tries to build an invalid page on purpose.

I'm not sure what the correct way to go here is and what needs to be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: nice to have Not breaking anything but nice to have (priority)
Projects
None yet
Development

No branches or pull requests

4 participants