-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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): domain with lookup table #9112
Conversation
|
8d5c500
to
951ad8a
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.
Added a review comment, thinking that having a full lookup table for all routes won't work.
* - `domain`: SSR only, it enables support for different domains. When a locale is mapped to domain, all the URLs won't have the language prefix. | ||
* You map `fr` to `fr.example.com`, if you want a to have a blog page to look like `fr.example.com/blog` instead of `example.com/fr/blog`. | ||
* The localised folders be must in the `src/pages/` folder. |
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 about how this works to be sure I understand:
- if you select
routingStrategy: "domain"
, what happens to the URLs for yourdefaultLocale
? Does it depend on whether you're using a/[defaultLocale]/
folder structure? Does it make any assumptions by default? - Is it correct to assume that for non-default locales, which will all be written in
/locale/
folders, that the URLs will be prefixed if you don't specifically add them todomains
? So, it's possible for a site to have a mixture of e.g.example.com/fr/
andes.example.com
? - is
domains
ignored ifroutingStrategy
is set to one of the two other options? Could it cause problems to havedomains
configured if you do NOT havedomain
set as your routing strategy? - Does the order of
domains
androutingStrategy
matter in thei18n
configuration? Could someone run into trouble if these are not in the proper order? - Looking at the example below,
routingStrategy
is outside of the object containing the other config options. In the docs, we show it as inside this object. Can you confirm which should be correct?
Thanks!
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.
- Yeah, there are assumptions. If you want to map a locale to a domain, the locale folder must be at
src/pages/[locale]
. The same goes for thedefaultLocale
. If the default locale isn't mapped to a domain, there aren't any assumptions. Although we are still evaluating the behaviour ofdefaultLocale
, so it's possible we will change it soon. - Yes, that is correct.
- No, that will be an error. For example, if you have
i18n.domains
androutingStategy: "prefix-always"
, Astro will throw a validation nerror. - No, the order doesn't matter.
- Mmmmh,
routingStategy
is inside thei18n
, same goes fordomains
. Are you referring to something else?
I'm also pointing out that #9099 was merged without my seeing it, which becomes confusing because now those docs changes do not show up as new here. |
Don't worry Sarah, I haven't requested your review for that PR on purpose. I will loop you in when I require your review. These PR aren't published yet on |
But you did request me on this one which has those changes in it already, so I'll just point out that it's very difficult for me to look at these individual pieces in isolation like this. These concepts don't exist independently from each other, and much of documentation is about how the whole picture works and the pieces fit together. Should I not be looking at this one yet? Edit: Sorry, I realized that "PTAL" is pretty broad, and maybe you weren't asking me to edit these yet, but maybe to give feedback or comment? As you saw, I couldn't really look at wording until it was clearer to me how things worked. Maybe PTAL in this case was actually Please Throw Your Questions At Me Now! I should have asked you to clarify what I was taking a look at/for and what would be helpful for you! (I'm sorry, I just got confused seeing docs merged that I hadn't seen related to this, and didn't know that I wasn't supposed to pay attention to them, because we're always trying to document all the features in relation to each other. So if it's there, I'm going to check that it's all consistent!) |
0030667
to
f244a0d
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.
lgtm!
* i18n(domains): validation and updated logic (#9099) * feat(i18n): domain with lookup table (#9112) * chore: add changelog, fix types and enable experimental support in node/vercel * rebase and update lock file * chore: fix failing test * Apply suggestions from code review Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> Co-authored-by: Matthew Phillips <matthew@skypack.dev> * Update .changeset/tidy-carrots-jump.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * wip * chore: rebase, conflicts and tests * update lock file * chore: correct configuration * chore: correct configuration * fix: regressions * chore: fix conflicts and add more tests * chore: add more validation * chore: more tests and add more restrictions * fix changeset * change and revert adapters * add another restriction * lock file update * Update packages/astro/src/@types/astro.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update packages/astro/src/@types/astro.ts Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com> * wat * fix syntax error * fix config example * Fix for #9673 (#9680) * Fix for #9673 * 🦋 add changeset file * Update breezy-plants-smoke.md Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev> * ⚡️ simplified normalizeConfigPath --------- Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev> * Fix env var replacement for export const prerender (#9807) * feat(alpinejs): allow customizing the Alpine instance (#9751) * feat(alpinejs): allows customzing the Alpine instance * chore: add e2e tests * fix: rename script * Update index.ts * fix: lockfile * [ci] format * chore: use correct lock file * chore: rebase * fix regressions in tests * fix regressions in tests * fix build * add description * fix missing types * chore: fix tests, again :D * eslint * Update packages/astro/src/@types/astro.ts Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> * chore: address feedback * chore: fix regressions * chore: refactor naming * Update packages/astro/src/core/app/index.ts Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com> * chore: address feedback * update lock file * chore: infer routing from options, not strategy * merge from main * merge from main * Experimental support in vercel adapter * Update packages/astro/src/@types/astro.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update packages/astro/src/@types/astro.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/tidy-carrots-jump.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * better changesets * Updates both experimental.i18nDomains and i18ndomains for experimental strategy * fix link syntax * consistent tabs/spaces * Update packages/astro/src/@types/astro.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * apply suggestion --------- Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> Co-authored-by: Matthew Phillips <matthew@skypack.dev> Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com> Co-authored-by: Lou Cyx <git@lou.cx> Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev> Co-authored-by: Florian Lefebvre <ematipico@users.noreply.github.com> Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
Changes
Relative RFC change: withastro/roadmap@713fce7
This PR adds the basic logic for supporting the new routing strategy called
domain
. We require a new routing strategy because Astro needs to make assumptions** in order to provide the correct user experience.This assumption is that the localised folders must be at the root -
src/pages
folder. With that, the logic works as follow: during the build phase, we add to the manifest a new information calleddomainLookupTable
. This table is a map that will look like this:It's essentially the configuration of
i18n.domains
, reversed :)This table maps what we are supposed to get from the server to the correct route. When we extract the correct route, we can load and render the component for that route.
In a server environment, Astro will work with the following headers:
X-Forwarded-Host
If Astro can't crate a
URL
from those heasers, it will return a 404. I believe this is an important information and I will make sure to add it to the RFC later.I will have to do some testing, even on a serverless environment and check if that information is available. I want to do more testing after merging this PR.
Closes PLT-1218
Testing
I added some basic testing to show the feature, although I want to add more tests in another PR.
Docs
/cc @withastro/maintainers-docs for feedback!