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

redirectDefaultLocale behaviour #37

Closed
dallyh opened this issue Dec 3, 2023 · 5 comments
Closed

redirectDefaultLocale behaviour #37

dallyh opened this issue Dec 3, 2023 · 5 comments

Comments

@dallyh
Copy link

dallyh commented Dec 3, 2023

Hello,

this is more of a question than issue.

I'm struggling a little bit with the redirectDefaultLocale option. I want my site to have paths for every language possible, that is for example "en, cs, fr" -> /en/page/, /cs/page/, /fr/page/.

When i set the redirectDefaultLocale to false, and my defaultLocale is "en", then /en/page/ returns 404. When the redirectDefaultLocale is in it's default state, then /en/page/ redirects to /page/. When I manually create /en/page/, then every other language is not automatically generated (404's).

Is it possible to make it so this integration generates paths for every language, even if it's the default one?

Thanks!

@jlarmstrongiv
Copy link
Owner

jlarmstrongiv commented Dec 3, 2023

Hi @dallyh,

This library is mostly meant to support the use-case of having a defaultLocale with Astro, without having to duplicate /about.astro and /es/about.astro

If you don’t want a defaultLocale, then you can use this Astro cookbook recipe or their upcoming their experimental router. Or, you can just use src/pages/[lang]/about.astro. I think those options are better for your use case, and do not plan to support it in this library. I hope these links point you in the right direction though

This library solves a problem that neither their cookbook nor experimental router solves—having a defaultLocale without page duplication


The redirectDefaultLocale controls the behavior of /en/about, when en is the defaultLocale. Setting redirectDefaultLocale means /en/about will redirect to /about, while setting it to false means /en/about will return a 404

@dallyh
Copy link
Author

dallyh commented Dec 3, 2023

@jlarmstrongiv

Thanks for the response, and I got it thanks.

But this integration solves more than the defaultLocale and that is, it solves the manual work required (set up every page individually) to use either the cookbook recipe or experimental router. Of course I could set up a script that does this for me, but this integration does everything conveniently in the background with minimal configuration. So for me a "mode" where it could generate paths for every language (and maybe discard the default ones, or redirect it the other way around) could be great in this combination.

So I would like to reopen this for further discussion (if possible) from your side.

@jlarmstrongiv
Copy link
Owner

@dallyh the src/pages/[lang]/about.astro should allow you to use one Astro page for all of your locales. You may have to define/pass your locales (["en", "es"]) in getStaticPaths or in SSR, but it should let you skip creating files like /en/about.astro and /es/about.astro. You may have to write your own helper functions to make it more ergonomic though. A custom 404 page (if using SSG) or custom middleware (if using SSR) could handle your defaultLocale redirects with that approach.

Having the options to avoid using a defaultLocale or redirect the defaultLocale to its prefixed path /en/about would pretty much mean re-writing this library. It’s certainly possible, but would take time to write, manually test all configuration options, and review. Are you interested in contributing this refactor?

For your particular use case without a defaultLocale, I think sticking with those Astro options is probably the easiest path forward for you. Plus, it avoids #19.

@dallyh
Copy link
Author

dallyh commented Dec 5, 2023

@jlarmstrongiv Thanks for your help and explanation, I appreciate it. I don't feel like a developer that could handle such task of refactoring the whole library.

The combination of dynamic [lang] path and Astro's new i18n router works well, but there are some quirks as of now.

Again thanks for all the information :)

@jlarmstrongiv
Copy link
Owner

@dallyh it’s certainly possible—I rewrote the library once to support the base option. But, it’s definitely a lot faster to use the dynamic [lang] path. Anyway, glad the suggestions helped 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants