-
-
Notifications
You must be signed in to change notification settings - Fork 233
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: add LocalePrefix never option #388
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@boris-arkenaar is attempting to deploy a commit to the next-intl Team on Vercel. A member of the Team first needs to authorize it. |
30f885a
to
2204613
Compare
@amannn Could you do a review? |
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.
What a fantastic PR, thank you for the great work! 🙌
I've played a bit with the example-next-13
app in this repo to test the new option and everything looks good to me. It seems like when you continuously switch the locale, at some point Next.js will returned a cached response, which will result in the cookie not being updated. I think there's a chance that the situation here will improve with #149, once we integrate createServerContext
. But for the time being this should be fine and I think for a natural user flow (i.e. not randomly switching between languages), this shouldn't be an issue.
I've published a prerelease of this feature:
next-intl@2.18.0-alpha.1
Would you like to try this out in your app to see if everything works as expected there?
}); | ||
|
||
it('rewrites requests for other locales at a nested path', () => { | ||
middleware(createMockRequest('/list', 'de')); |
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.
Can you also include some tests where the accept-language
header and the cookie value don't match while no locale is in the pathname? The cookie value should have precedence in this case.
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.
Of course.
configWithDefaults.localePrefix === 'never' || | ||
(hasMatchedDefaultLocale && | ||
(configWithDefaults.localePrefix === 'as-needed' || | ||
configWithDefaults.domains)) |
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'm wondering what we should do with the alternate links in case of localePrefix: 'never'
(see L198 below).
SEO is not really an issue here, but maybe some assistive technology will still read the header.
Here's an example for /about
when I have NEXT_LOCALE=de
:
Link:
<http://localhost:3000/about>; rel="alternate"; hreflang="en",
<http://localhost:3000/de/about>; rel="alternate"; hreflang="de",
<http://localhost:3000/about>; rel="alternate"; hreflang="x-default"
This seems somewhat off, probably we should adjust the links to match this:
Link:
<http://localhost:3000/about>; rel="alternate"; hreflang="de",
<http://localhost:3000/en/about>; rel="alternate"; hreflang="en",
<http://localhost:3000/about>; rel="alternate"; hreflang="x-default"
Would you mind looking into this?
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.
Alternate links don't really make sense in this case, since the URL won't set or change the current locale, right?
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.
Or you could actually. It's some 'hidden' functionality at the moment I believe. When you go to a URL prefixed with a locale it will set that locale in the cookie and redirect to the URL without the locale prefix.
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.
Maybe more explicit then, like this?
Link:
<http://localhost:3000/de/about>; rel="alternate"; hreflang="de",
<http://localhost:3000/en/about>; rel="alternate"; hreflang="en",
<http://localhost:3000/about>; rel="alternate"; hreflang="x-default"
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.
Cannot find anything about screen readers and the use of alternate link headers though.
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.
Maybe leave it out for locale prefix never
?
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.
Sure, that's the other option. Fine by me, but we should mention it in the docs then!
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.
Disabling the alternate links and a brief mention in the docs would be the last part missing here, afterwards we can release this!
``` | ||
|
||
In this case all requests for all locales will be rewritten internally. | ||
|
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.
Well written 👌
Thanks for the pre-release. Tested with my app. Seems to be working well here as well! |
Oh, wait. Still running my custom middleware. Let me set it up properly now. |
Got it. Seems to work great :) |
@boris-arkenaar Do you have the time to complete this or can I help with something? (see the last open point) |
@amannn You mean about the alternate links? Missed that comment. I can update that soon. |
@boris-arkenaar Yep, correct! Thank you so much! 🙌 |
@amannn Updated code and docs. Wanted to add some tests as well, but couldn't figure out how to mock/spy on |
Thank you so much! I've added a commit with minor fixes, including a fix for the mock behavior in the middleware and tests for the alternate links. Will merge and release this once CI is green, thank you so much for the great contribution! 🙌 |
fixes #366