-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
chore(i18n): reworked fallback, docs, types and validation #8995
Conversation
|
fc93dbb
to
71f94fb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are fabulous updates! Just a few minor suggestions. Thank you for hanging in there with me as I try to get all of these options straight in my head. 😅
packages/astro/src/@types/astro.ts
Outdated
* The content fallback strategy when navigating to pages in non-default languages that do not exist. (e.g. a translated page has not been created). | ||
* | ||
* This a plain object, where a key is a locale that hasn't traslated pages, and the corresponding value is the locale where you want to redirect the missing page to. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* The content fallback strategy when navigating to pages in non-default languages that do not exist. (e.g. a translated page has not been created). | |
* | |
* This a plain object, where a key is a locale that hasn't traslated pages, and the corresponding value is the locale where you want to redirect the missing page to. | |
* The content fallback strategy when navigating to pages in non-default languages that do not exist (e.g. a translated page has not been created). | |
* | |
* Use this object to declare a fallback `locale` for each language you support individually. If no fallback is specified, then unavailable pages will return a 404. |
This looks great!
I made up that sentence at the end, because I think it helps to say what happens if you don't configure anything.
I think a common thing to want to do here will be to make the one default fallback, and not have to list every language out individually. So, if the above is true, that's also very useful for doing this! If the above is NOT true, then I think we need to tell them how to set one default language for all other languages, as I expect this to be a common use case.
EDIT: changed "then all languages listed in locales
will redirect the page to your defaultLocale
"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason why I haven't put any default fallback is because:
- we do want to avoid redirects as much as possible as default behaviour
- it's possible that users don't require this feature (localised market, legal documents, etc.), so it would get more complicated to opt out of the default behaviour
About this suggestion:
If no fallback is specified, then all languages listed in
locales
will redirect the page to yourdefaultLocale
.
As for now, we won't redirect to the defaultLocale
, which means that if the user doesn't set a fallback for a locale, the missing pages will return 404.
We can explore a redirect behaviour later on
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the comment (and the other one) with acceptable placeholder language that I'll check on! This is good enough to merge!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for the logic changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving and my task is to make sure we're saying "returns a 404" properly and consistently before publishing! Great changes here!
71f94fb
to
177ee1f
Compare
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
Changes
There was some issue with the types of
i18n.fallback
, and I added another level of validation to zod.Testing
Added a test case to cover the new logic
Docs
/cc @withastro/maintainers-docs for feedback!
@sarah11918 we can use this PR to land the correct documentation for fallback