-
-
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
feat(i18n): expand fallback system #11677
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a7391ef
feat(i18n): expand fallback system
ematipico 7827980
rebase
ematipico 872dae3
apply feedback
ematipico e273fab
better changeset
ematipico fb1192e
update tests too
ematipico 67c2030
apply feedback
ematipico b0bb20d
Update .changeset/blue-pens-divide.md
ematipico b95f32d
update docs
ematipico 0d6884a
nitpick
ematipico 80b1c6a
Apply suggestions from code review
ematipico 6f54756
Update .changeset/blue-pens-divide.md
ematipico 2089a3f
Apply suggestions from code review
ematipico f712640
Update .changeset/blue-pens-divide.md
ematipico a42d513
fix regression
ematipico File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Fixes a bug in the logic of `Astro.rewrite()` which led to the value for `base`, if configured, being automatically prepended to the rewrite URL passed. This was unintended behavior and has been corrected, and Astro now processes the URLs exactly as passed. | ||
|
||
If you use the `rewrite()` function on a project that has `base` configured, you must now prepend the base to your existing rewrite URL: | ||
|
||
```js | ||
// astro.config.mjs | ||
export default defineConfig({ | ||
base: '/blog' | ||
}) | ||
``` | ||
|
||
```diff | ||
// src/middleware.js | ||
export function onRequest(ctx, next) { | ||
- return ctx.rewrite("/about") | ||
+ return ctx.rewrite("/blog/about") | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
'astro': minor | ||
--- | ||
|
||
Adds a new option `fallbackType` to `i18n.routing` configuration that allows you to control how fallback pages are handled. | ||
|
||
When `i18n.fallback` is configured, this new routing option controls whether to [redirect](https://docs.astro.build/en/guides/routing/#redirects) to the fallback page, or to [rewrite](https://docs.astro.build/en/guides/routing/#rewrites) the fallback page's content in place. | ||
|
||
The `"redirect"` option is the default value and matches the current behavior of the existing fallback system. | ||
|
||
The option `"rewrite"` uses the new [rewriting system](https://docs.astro.build/en/guides/routing/#rewrites) to create fallback pages that render content on the original, requested URL without a browser refresh. | ||
|
||
For example, the following configuration will generate a page `/fr/index.html` that will contain the same HTML rendered by the page `/en/index.html` when `src/pages/fr/index.astro` does not exist. | ||
|
||
```js | ||
// astro.config.mjs | ||
export default defineConfig({ | ||
i18n: { | ||
locals: ["en", "fr"], | ||
defaultLocale: "en", | ||
routing: { | ||
prefixDefaultLocale: true, | ||
fallbackType: "rewrite" | ||
}, | ||
fallback: { | ||
fr: "en" | ||
}, | ||
} | ||
}) | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I have some questions first here @ematipico
Is this top-level i18n config? Is this entry in the correct place? Right now, it would be showing up between two
i18n.routing.*
entries.Shouldn't it also be near
i18n.fallback
? And, this doesn't replace it, but is a separate, same-level configuration? (that's up around line 1567).I think we should also see an example of both this and fallback configured together in one code sample, since I'm assuming they'd need to work together. Without any
i18n.fallback
configured, you default to showing 404s for pages that don't exist, so you can't have a strategy?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.
It should be
i18n.routing.fallbackType
. I will update the code, because it's incorrect.I updated the docs with an example here
2447fb9
(#11677)