Skip to content
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 #1657] Setup Next-Intl for App Pages #1851

Merged
merged 12 commits into from May 7, 2024
Merged

Conversation

acouch
Copy link
Collaborator

@acouch acouch commented Apr 26, 2024

Summary

Fixes #1657

Time to review: 30 mins

Changes proposed

Enables next-intl to enable translation for app pages. This sets up next-intl and enables it for the search page and app not found page. This adds one other app component. There are three which will be removed for #1361 .

Context for reviewers

The strings being declared and injected is still ugly and not addressed with this, but will be fixed with #1361 .

The [locale] folder has not been setup yet b/c it took over the full routing for the site. That folder will be setup in #1361 .

return meta;
}

export default async function Help() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You use useTransations() and useMessages() if it is a sync function.

Copy link
Collaborator

@rylew1 rylew1 Apr 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Believe all use* hooks are typically only be used by client components (useSearchParams, useEffect, useState). So its a bit weird to see next-intl using them in server components https://next-intl-docs.vercel.app/docs/environments/server-client-components

@@ -0,0 +1,54 @@
import { Metadata } from "next";
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This page was just for playing around, will delete.

@acouch acouch force-pushed the acouch/issue-1657-next-intl branch from 627928b to 9941fb8 Compare April 30, 2024 15:20
@acouch
Copy link
Collaborator Author

acouch commented Apr 30, 2024

This is green except for a single test for the AppLayout.tsx:

Error: `getTranslations` is not supported in Client Components.
    at /home/runner/work/simpler-grants-gov/simpler-grants-gov/frontend/node_modules/next-intl/dist/development/server/react-client/index.js:15:11
    at Layout (/home/runner/work/simpler-grants-gov/simpler-grants-gov/frontend/src/components/AppLayout.tsx:399:63)
    at renderWithHooks (/home/runner/work/simpler-grants-gov/simpler-grants-gov/frontend/node_modules/react-dom/cjs/react-dom.development.js:16305:18)

It is not a client component AFAICT, so not sure what the deal here is.

@acouch acouch force-pushed the acouch/issue-1657-next-intl branch from a866c45 to 224d6a3 Compare April 30, 2024 18:57
@rylew1
Copy link
Collaborator

rylew1 commented Apr 30, 2024

This is green except for a single test for the AppLayout.tsx:

Error: `getTranslations` is not supported in Client Components.
    at /home/runner/work/simpler-grants-gov/simpler-grants-gov/frontend/node_modules/next-intl/dist/development/server/react-client/index.js:15:11
    at Layout (/home/runner/work/simpler-grants-gov/simpler-grants-gov/frontend/src/components/AppLayout.tsx:399:63)
    at renderWithHooks (/home/runner/work/simpler-grants-gov/simpler-grants-gov/frontend/node_modules/react-dom/cjs/react-dom.development.js:16305:18)
It is not a client component AFAICT, so not sure what the deal here is.

I console logged in AppLayout and it only showed on the server. Wonder if the new next-intl changes are properly configured to support server components or otherwise causing things to rendier client side?

Also wondering if AppLayout needs to be an async component?

I'm not fully capacity at the moment but I should be able to help debug this better on Thursday if it's still an issue.

Copy link

github-actions bot commented May 1, 2024

Coverage report for ./frontend

St.
Category Percentage Covered / Total
🟢 Statements
84.06% (+0.17% 🔼)
870/1035
🟡 Branches
65.12% (+0.22% 🔼)
224/344
🟡 Functions
75.57% (+0.22% 🔼)
167/221
🟢 Lines
84.11% (+0.22% 🔼)
810/963
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / react-utils.tsx
100% 100% 100% 100%
🟢 src/i18n/config.ts 87.5% 100% 100% 100%
🟢
... / index.ts
100% 100% 100% 100%

Test suite run success

166 tests passing in 55 suites.

Report generated by 🧪jest coverage report action from c090e9b


const BetaAlert = () => {
const t = useTranslations("Beta_alert");
const heading = t.rich("alert_title", {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file was added until #1361

Copy link
Collaborator

@rylew1 rylew1 May 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a comment in the code that points to that ticket? Format we've been using is // TODO (Issue #1361): ....

Same thing for AppLayout file or other places

// TODO: Remove during move to app router and next-intl upgrade
export default function Layout({ children, locale }: Props) {
const t = useTranslations();

const header_strings = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These strings will be removed once we moved the app router and are no longer using both i18n and next-intl in #1361

@acouch acouch force-pushed the acouch/issue-1657-next-intl branch from 61ab471 to 3afbf5d Compare May 1, 2024 02:46
@acouch acouch marked this pull request as ready for review May 1, 2024 02:51
@acouch
Copy link
Collaborator Author

acouch commented May 6, 2024

Met with @rylew1 , want to look more closely at how the browser locale works and how to only allow the selected locales in the routing layer.

@acouch
Copy link
Collaborator Author

acouch commented May 6, 2024

@rylew1 The PR does remove non language routes, I just had the [locale] folder in place locally w/o the rest of the config. The browser locale docs explain the browser config strategy. Think we are good to go.

@acouch acouch merged commit 35d6fe5 into main May 7, 2024
10 checks passed
@acouch acouch deleted the acouch/issue-1657-next-intl branch May 7, 2024 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task]: Setup i18n with next-intl
2 participants