Skip to content

Commit

Permalink
rolling out removal of hardcoded locale
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-s-nava committed Dec 12, 2024
1 parent b843146 commit 3a29c5c
Show file tree
Hide file tree
Showing 21 changed files with 140 additions and 80 deletions.
7 changes: 5 additions & 2 deletions frontend/src/app/[locale]/[...not-found]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Metadata } from "next";
import { LocalizedPageProps } from "src/types/intl";

import { getTranslations } from "next-intl/server";
import { notFound } from "next/navigation";

export async function generateMetadata() {
const t = await getTranslations({ locale: "en" });
export async function generateMetadata({
params: { locale },
}: LocalizedPageProps) {
const t = await getTranslations({ locale });
const meta: Metadata = {
title: t("ErrorPages.page_not_found.title"),
description: t("Index.meta_description"),
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Script from "next/script";
import "src/styles/styles.scss";

import { NextIntlClientProvider } from "next-intl";
import { getMessages, unstable_setRequestLocale } from "next-intl/server";
import { getMessages, setRequestLocale } from "next-intl/server";

import Layout from "src/components/Layout";

Expand Down Expand Up @@ -61,7 +61,7 @@ export default async function LocaleLayout({ children, params }: Props) {
const { locale } = params;

// Enable static rendering
unstable_setRequestLocale(locale);
setRequestLocale(locale);

// Providing all messages to the client
// side is the easiest way to get started
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/app/[locale]/not-found.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { Metadata } from "next";

import { useTranslations } from "next-intl";
import { getTranslations, unstable_setRequestLocale } from "next-intl/server";
import { getTranslations } from "next-intl/server";
import Link from "next/link";
import { GridContainer } from "@trussworks/react-uswds";

import BetaAlert from "src/components/BetaAlert";

export async function generateMetadata() {
const t = await getTranslations({ locale: "en" });
const t = await getTranslations();
const meta: Metadata = {
title: t("ErrorPages.page_not_found.title"),
description: t("Index.meta_description"),
};
return meta;
}

// note that NotFound pages do not take props so cannot be translated
export default function NotFound() {
unstable_setRequestLocale("en");
const t = useTranslations("ErrorPages.page_not_found");

return (
Expand Down
11 changes: 8 additions & 3 deletions frontend/src/app/[locale]/opportunity/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ import OpportunityStatusWidget from "src/components/opportunity/OpportunityStatu

export const revalidate = 600; // invalidate ten minutes

export async function generateMetadata({ params }: { params: { id: string } }) {
const t = await getTranslations({ locale: "en" });
export async function generateMetadata({
params,
}: {
params: { id: string; locale: string };
}) {
const { id, locale } = params;
const t = await getTranslations({ locale });
let title = `${t("OpportunityListing.page_title")}`;
try {
const { data: opportunityData } = await fetchOpportunity({
subPath: params.id,
subPath: id,
});
title = `${t("OpportunityListing.page_title")} - ${opportunityData.opportunity_title}`;
} catch (error) {
Expand Down
13 changes: 8 additions & 5 deletions frontend/src/app/[locale]/process/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@ import ProcessIntro from "src/app/[locale]/process/ProcessIntro";
import ProcessInvolved from "src/app/[locale]/process/ProcessInvolved";
import ProcessMilestones from "src/app/[locale]/process/ProcessMilestones";
import { PROCESS_CRUMBS } from "src/constants/breadcrumbs";
import { LocalizedPageProps } from "src/types/intl";

import { getTranslations, unstable_setRequestLocale } from "next-intl/server";
import { getTranslations, setRequestLocale } from "next-intl/server";

import BetaAlert from "src/components/BetaAlert";
import Breadcrumbs from "src/components/Breadcrumbs";

export async function generateMetadata() {
const t = await getTranslations({ locale: "en" });
export async function generateMetadata({
params: { locale },
}: LocalizedPageProps) {
const t = await getTranslations({ locale });
const meta: Metadata = {
title: t("Process.page_title"),
description: t("Process.meta_description"),
};
return meta;
}

export default function Process() {
unstable_setRequestLocale("en");
export default function Process({ params: { locale } }: LocalizedPageProps) {
setRequestLocale(locale);
return (
<>
<BetaAlert />
Expand Down
13 changes: 8 additions & 5 deletions frontend/src/app/[locale]/research/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,26 @@ import ResearchIntro from "src/app/[locale]/research/ResearchIntro";
import ResearchMethodology from "src/app/[locale]/research/ResearchMethodology";
import ResearchThemes from "src/app/[locale]/research/ResearchThemes";
import { RESEARCH_CRUMBS } from "src/constants/breadcrumbs";
import { LocalizedPageProps } from "src/types/intl";

import { getTranslations, unstable_setRequestLocale } from "next-intl/server";
import { getTranslations, setRequestLocale } from "next-intl/server";

import BetaAlert from "src/components/BetaAlert";
import Breadcrumbs from "src/components/Breadcrumbs";

export async function generateMetadata() {
const t = await getTranslations({ locale: "en" });
export async function generateMetadata({
params: { locale },
}: LocalizedPageProps) {
const t = await getTranslations({ locale });
const meta: Metadata = {
title: t("Research.page_title"),
description: t("Research.meta_description"),
};
return meta;
}

export default function Research() {
unstable_setRequestLocale("en");
export default function Research({ params: { locale } }: LocalizedPageProps) {
setRequestLocale(locale);
return (
<>
<BetaAlert />
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/app/[locale]/search/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { SEARCH_CRUMBS } from "src/constants/breadcrumbs";

import { unstable_setRequestLocale } from "next-intl/server";
import { setRequestLocale } from "next-intl/server";

import BetaAlert from "src/components/BetaAlert";
import Breadcrumbs from "src/components/Breadcrumbs";
import SearchCallToAction from "src/components/search/SearchCallToAction";

export default function SearchLayout({
children,
params: { locale },
}: {
children: React.ReactNode;
params: {
locale: string;
};
}) {
unstable_setRequestLocale("en");
setRequestLocale(locale);
return (
<>
<BetaAlert />
Expand Down
19 changes: 14 additions & 5 deletions frontend/src/app/[locale]/search/page.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
import { Metadata } from "next";
import QueryProvider from "src/app/[locale]/search/QueryProvider";
import withFeatureFlag from "src/hoc/search/withFeatureFlag";
import { LocalizedPageProps } from "src/types/intl";
import { SearchParamsTypes } from "src/types/search/searchRequestTypes";
import { Breakpoints } from "src/types/uiTypes";
import { convertSearchParamsToProperTypes } from "src/utils/search/convertSearchParamsToProperTypes";

import { useTranslations } from "next-intl";
import { getTranslations, unstable_setRequestLocale } from "next-intl/server";
import { getTranslations, setRequestLocale } from "next-intl/server";

import ContentDisplayToggle from "src/components/ContentDisplayToggle";
import SearchAnalytics from "src/components/search/SearchAnalytics";
import SearchBar from "src/components/search/SearchBar";
import SearchFilters from "src/components/search/SearchFilters";
import SearchResults from "src/components/search/SearchResults";

export async function generateMetadata() {
const t = await getTranslations({ locale: "en" });
export async function generateMetadata({
params: { locale },
}: LocalizedPageProps) {
const t = await getTranslations({ locale });
const meta: Metadata = {
title: t("Search.title"),
description: t("Index.meta_description"),
};
return meta;
}
function Search({ searchParams }: { searchParams: SearchParamsTypes }) {
unstable_setRequestLocale("en");
function Search({
searchParams,
params: { locale },
}: {
searchParams: SearchParamsTypes;
params: { locale: string };
}) {
setRequestLocale(locale);
const t = useTranslations("Search");

const convertedSearchParams = convertSearchParamsToProperTypes(searchParams);
Expand Down
15 changes: 10 additions & 5 deletions frontend/src/app/[locale]/subscribe/confirmation/page.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { Metadata } from "next";
import { SUBSCRIBE_CONFIRMATION_CRUMBS } from "src/constants/breadcrumbs";
import { LocalizedPageProps } from "src/types/intl";

import { useTranslations } from "next-intl";
import { getTranslations, unstable_setRequestLocale } from "next-intl/server";
import { getTranslations, setRequestLocale } from "next-intl/server";
import Link from "next/link";
import { Grid, GridContainer } from "@trussworks/react-uswds";

import BetaAlert from "src/components/BetaAlert";
import Breadcrumbs from "src/components/Breadcrumbs";

export async function generateMetadata() {
const t = await getTranslations({ locale: "en" });
export async function generateMetadata({
params: { locale },
}: LocalizedPageProps) {
const t = await getTranslations({ locale });
const meta: Metadata = {
title: t("Subscribe.page_title"),
description: t("Index.meta_description"),
Expand All @@ -19,8 +22,10 @@ export async function generateMetadata() {
return meta;
}

export default function SubscriptionConfirmation() {
unstable_setRequestLocale("en");
export default function SubscriptionConfirmation({
params: { locale },
}: LocalizedPageProps) {
setRequestLocale(locale);
const t = useTranslations("Subscription_confirmation");

return (
Expand Down
28 changes: 10 additions & 18 deletions frontend/src/app/[locale]/subscribe/page.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import pick from "lodash/pick";
import { Metadata } from "next";
import { SUBSCRIBE_CRUMBS } from "src/constants/breadcrumbs";
import { LocalizedPageProps } from "src/types/intl";

import {
NextIntlClientProvider,
useMessages,
useTranslations,
} from "next-intl";
import { getTranslations, unstable_setRequestLocale } from "next-intl/server";
import { useTranslations } from "next-intl";
import { getTranslations, setRequestLocale } from "next-intl/server";
import { Grid, GridContainer } from "@trussworks/react-uswds";

import BetaAlert from "src/components/BetaAlert";
import Breadcrumbs from "src/components/Breadcrumbs";
import SubscriptionForm from "src/components/subscribe/SubscriptionForm";

export async function generateMetadata() {
const t = await getTranslations({ locale: "en" });
export async function generateMetadata({
params: { locale },
}: LocalizedPageProps) {
const t = await getTranslations({ locale });
const meta: Metadata = {
title: t("Subscribe.page_title"),
description: t("Index.meta_description"),
Expand All @@ -24,10 +22,9 @@ export async function generateMetadata() {
return meta;
}

export default function Subscribe() {
unstable_setRequestLocale("en");
export default function Subscribe({ params: { locale } }: LocalizedPageProps) {
setRequestLocale(locale);
const t = useTranslations("Subscribe");
const messages = useMessages();

return (
<>
Expand All @@ -54,12 +51,7 @@ export default function Subscribe() {
})}
</Grid>
<Grid tabletLg={{ col: 6 }}>
<NextIntlClientProvider
locale="en"
messages={pick(messages, "Subscribe")}
>
<SubscriptionForm />
</NextIntlClientProvider>
<SubscriptionForm />
</Grid>
</Grid>
</GridContainer>
Expand Down
15 changes: 10 additions & 5 deletions frontend/src/app/[locale]/subscribe/unsubscribe/page.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { Metadata } from "next";
import { UNSUBSCRIBE_CRUMBS } from "src/constants/breadcrumbs";
import { LocalizedPageProps } from "src/types/intl";

import { useTranslations } from "next-intl";
import { getTranslations, unstable_setRequestLocale } from "next-intl/server";
import { getTranslations, setRequestLocale } from "next-intl/server";
import Link from "next/link";
import { Grid, GridContainer } from "@trussworks/react-uswds";

import BetaAlert from "src/components/BetaAlert";
import Breadcrumbs from "src/components/Breadcrumbs";

export async function generateMetadata() {
const t = await getTranslations({ locale: "en" });
export async function generateMetadata({
params: { locale },
}: LocalizedPageProps) {
const t = await getTranslations({ locale });
const meta: Metadata = {
title: t("Subscribe.page_title"),
description: t("Index.meta_description"),
Expand All @@ -19,8 +22,10 @@ export async function generateMetadata() {
return meta;
}

export default function Unsubscribe() {
unstable_setRequestLocale("en");
export default function Unsubscribe({
params: { locale },
}: LocalizedPageProps) {
setRequestLocale(locale);
const t = useTranslations("Unsubscription_confirmation");

return (
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
useMessages,
useTranslations,
} from "next-intl";
import { unstable_setRequestLocale } from "next-intl/server";
import { setRequestLocale } from "next-intl/server";

import Footer from "./Footer";
import GrantsIdentifier from "./GrantsIdentifier";
Expand All @@ -17,7 +17,7 @@ type Props = {
};

export default function Layout({ children, locale }: Props) {
unstable_setRequestLocale(locale);
setRequestLocale(locale);

const t = useTranslations();
const messages = useMessages();
Expand Down
14 changes: 13 additions & 1 deletion frontend/src/i18n/messages/es/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
export const messages = {};
export const messages = {
ErrorPages: {
page_not_found: {
title: "No pagina nunca",
},
},
Subscribe: {
form: {
name: "Nombre Primero",
lastName: "Nombre Ultimo",
},
},
};
2 changes: 1 addition & 1 deletion frontend/tests/components/search/SearchFilters.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jest.mock("src/hooks/useSearchParamUpdater", () => ({

jest.mock("next-intl/server", () => ({
getTranslations: () => identity,
unstable_setRequestLocale: identity,
setRequestLocale: identity,
}));

jest.mock("next-intl", () => ({
Expand Down
2 changes: 1 addition & 1 deletion frontend/tests/components/search/SearchResults.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jest.mock("src/hooks/useSearchParamUpdater", () => ({

jest.mock("next-intl/server", () => ({
getTranslations: () => identity,
unstable_setRequestLocale: identity,
setRequestLocale: identity,
}));

jest.mock("next-intl", () => ({
Expand Down
Loading

0 comments on commit 3a29c5c

Please sign in to comment.