-
Notifications
You must be signed in to change notification settings - Fork 16
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
[Issue #3078] cleanup translation related code #3089
Conversation
@@ -1,6 +1,6 @@ | |||
// @ts-check | |||
|
|||
const withNextIntl = require("next-intl/plugin")("./src/i18n/server.ts"); | |||
const withNextIntl = require("next-intl/plugin")(); |
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.
see https://next-intl-docs.vercel.app/docs/usage/configuration - using a request.ts file, config will get picked up automatically. Not sure why this was in server.ts
instead
@@ -16,15 +16,15 @@ jest.mock("next-intl", () => ({ | |||
|
|||
describe("Home", () => { | |||
it("renders intro text", () => { | |||
render(<Home />); | |||
render(Home({ params: { locale: "en" } })); |
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.
this is a bit unfortunate, but seems to be the best way to deal with testing a top level page that takes params from the Next system
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.
Was there a reason for renaming 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.
yeah, you can see my note in the config file - basically next intl will automatically pick up a file called request, whereas ours was called server and we had to pass a path to it to get it to work. Simplifies things slightly and makes use of built in behavior
@@ -54,12 +51,7 @@ export default function Subscribe() { | |||
})} | |||
</Grid> | |||
<Grid tabletLg={{ col: 6 }}> | |||
<NextIntlClientProvider |
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.
had to make this change to get tests to work, but this wasn't doing anything anyway
export default getRequestConfig(async ({ requestLocale }) => { | ||
let locale = (await requestLocale) || ""; | ||
|
||
const isValidLocale = locales.includes(locale); // https://github.com/microsoft/TypeScript/issues/26255 |
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.
moved this over from the getMessagesWithFallbacks
code. Not a necessary change but just made more sense to me to do the locale default logic as high up in the call stack as possible
32f13f3
to
b10c912
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.
🎉 🇪🇸 🚀 !
Summary
Fixes #3078
Time to review: 30 mins
Changes proposed
Context for reviewers
When testing translation behavior, it was difficult to track down why the Spanish version of the site was not loading. In the end, it was a matter of us manually setting "en" as the locale in a number of places unnecessarily. Since
getMessagesWithFallbacks
handles filling any missing messages in with English, so there isn't a need to manually setthe request locale to "en".
This change updates the entire app to support dynamically set locales.
It also:
set locale
methods (unstable_setRequestLocale is now stable, see feat: MarksetRequestLocale
as stable amannn/next-intl#1437)Test steps
Additional information