Skip to content

Commit

Permalink
feat(core): localize metadata titles (#1368)
Browse files Browse the repository at this point in the history
* feat(core): localize metadata titles

* fix: revert heading translations add address
  • Loading branch information
jorgemoya committed Sep 13, 2024
1 parent f37deb6 commit d032e65
Show file tree
Hide file tree
Showing 19 changed files with 127 additions and 50 deletions.
5 changes: 5 additions & 0 deletions .changeset/strong-penguins-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/catalyst-core": patch
---

Localize metadata titles.
11 changes: 8 additions & 3 deletions core/app/[locale]/(default)/(auth)/change-password/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { useTranslations } from 'next-intl';
import { getTranslations } from 'next-intl/server';

import { redirect } from '~/i18n/routing';

import { ChangePasswordForm } from './_components/change-password-form';

export const metadata = {
title: 'Change password',
};
export async function generateMetadata() {
const t = await getTranslations('ChangePassword');

return {
title: t('title'),
};
}

interface Props {
searchParams: {
Expand Down
12 changes: 8 additions & 4 deletions core/app/[locale]/(default)/(auth)/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { useTranslations } from 'next-intl';
import { unstable_setRequestLocale } from 'next-intl/server';
import { getTranslations, unstable_setRequestLocale } from 'next-intl/server';

import { Link } from '~/components/link';
import { Button } from '~/components/ui/button';
import { locales, LocaleType } from '~/i18n/routing';

import { LoginForm } from './_components/login-form';

export const metadata = {
title: 'Login',
};
export async function generateMetadata() {
const t = await getTranslations('Login');

return {
title: t('title'),
};
}

interface Props {
params: { locale: LocaleType };
Expand Down
10 changes: 7 additions & 3 deletions core/app/[locale]/(default)/(auth)/register/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ const FALLBACK_COUNTRY = {
code: 'US',
};

export const metadata = {
title: 'Register account',
};
export async function generateMetadata() {
const t = await getTranslations('Register');

return {
title: t('title'),
};
}

export default async function Register() {
const t = await getTranslations('Register');
Expand Down
10 changes: 7 additions & 3 deletions core/app/[locale]/(default)/(auth)/reset/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ const ResetPageQuery = graphql(
[ResetPasswordFormFragment],
);

export const metadata = {
title: 'Reset password',
};
export async function generateMetadata() {
const t = await getTranslations('Reset');

return {
title: t('title'),
};
}

export default async function Reset() {
const t = await getTranslations('Reset');
Expand Down
10 changes: 7 additions & 3 deletions core/app/[locale]/(default)/(faceted)/search/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ import { MobileSideNav } from '../_components/mobile-side-nav';
import { SortBy } from '../_components/sort-by';
import { fetchFacetedSearch } from '../fetch-faceted-search';

export const metadata = {
title: 'Search Results',
};
export async function generateMetadata() {
const t = await getTranslations('Search');

return {
title: t('title'),
};
}

interface Props {
searchParams: Record<string, string | string[] | undefined>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ const FALLBACK_COUNTRY = {
states: [],
};

export const metadata = {
title: 'Add address',
};
export async function generateMetadata() {
const t = await getTranslations('Account.Addresses.Add');

return {
title: t('title'),
};
}

export default async function AddPage() {
const t = await getTranslations('Account.Addresses.Add');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,13 @@ const CustomerEditAddressQuery = graphql(

export type CustomerEditAddressQueryResult = ResultOf<typeof CustomerEditAddressQuery>;

export const metadata = {
title: 'Edit address',
};
export async function generateMetadata() {
const t = await getTranslations('Account.Addresses.Edit');

return {
title: t('title'),
};
}

interface Props {
params: { slug: string };
Expand Down
11 changes: 8 additions & 3 deletions core/app/[locale]/(default)/account/(tabs)/addresses/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { notFound } from 'next/navigation';
import { getTranslations } from 'next-intl/server';

import { Pagination } from '~/components/ui/pagination';

Expand All @@ -15,9 +16,13 @@ interface Props {
};
}

export const metadata = {
title: 'Addresses',
};
export async function generateMetadata() {
const t = await getTranslations('Account.Addresses');

return {
title: t('title'),
};
}

export default async function Addresses({ searchParams }: Props) {
const { before, after } = searchParams;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { unstable_setRequestLocale } from 'next-intl/server';
import { getTranslations, unstable_setRequestLocale } from 'next-intl/server';

import { locales, LocaleType } from '~/i18n/routing';

import { TabHeading } from '../../_components/tab-heading';

import { ChangePasswordForm } from './_components/change-password-form';

export const metadata = {
title: 'Change password',
};
export async function generateMetadata() {
const t = await getTranslations('Account.Settings.ChangePassword');

return {
title: t('title'),
};
}

interface Props {
params: { locale: LocaleType };
Expand Down
9 changes: 9 additions & 0 deletions core/app/[locale]/(default)/account/(tabs)/settings/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { notFound } from 'next/navigation';
import { getTranslations } from 'next-intl/server';

import { TabHeading } from '../_components/tab-heading';

import { UpdateSettingsForm } from './_components/update-settings-form';
import { getCustomerSettingsQuery } from './page-data';

export async function generateMetadata() {
const t = await getTranslations('Account.Settings');

return {
title: t('title'),
};
}

export default async function Settings() {
const customerSettings = await getCustomerSettingsQuery({
address: { filters: { entityIds: [4, 5, 6, 7] } },
Expand Down
4 changes: 3 additions & 1 deletion core/app/[locale]/(default)/blog/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Metadata } from 'next';
import { notFound } from 'next/navigation';
import { getTranslations } from 'next-intl/server';

import { BlogPostCard } from '~/components/blog-post-card';
import { Pagination } from '~/components/ui/pagination';
Expand All @@ -13,10 +14,11 @@ interface Props {
}

export async function generateMetadata({ searchParams }: Props): Promise<Metadata> {
const t = await getTranslations('Blog');
const blogPosts = await getBlogPosts(searchParams);

return {
title: blogPosts?.name ?? 'Blog',
title: blogPosts?.name ?? t('title'),
description:
blogPosts?.description && blogPosts.description.length > 150
? `${blogPosts.description.substring(0, 150)}...`
Expand Down
10 changes: 7 additions & 3 deletions core/app/[locale]/(default)/cart/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ const CartPageQuery = graphql(
[CartItemFragment, CheckoutSummaryFragment, GeographyFragment],
);

export const metadata = {
title: 'Cart',
};
export async function generateMetadata() {
const t = await getTranslations('Cart');

return {
title: t('title'),
};
}

export default async function Cart() {
const cartId = cookies().get('cartId')?.value;
Expand Down
10 changes: 7 additions & 3 deletions core/app/[locale]/(default)/compare/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ const ComparePageQuery = graphql(
[AddToCartFragment, PricingFragment],
);

export const metadata = {
title: 'Compare',
};
export async function generateMetadata() {
const t = await getTranslations('Compare');

return {
title: t('title'),
};
}

interface Props {
searchParams: Record<string, string | string[] | undefined>;
Expand Down
4 changes: 0 additions & 4 deletions core/app/[locale]/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,4 @@

import { lazy } from 'react';

export const metadata = {
title: 'Error',
};

export default lazy(() => import('./_components/error'));
10 changes: 7 additions & 3 deletions core/app/[locale]/maintenance/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ const MaintenancePageQuery = graphql(
[StoreLogoFragment],
);

export const metadata = {
title: 'Maintenance',
};
export async function generateMetadata() {
const t = await getTranslations('Maintenance');

return {
title: t('title'),
};
}

const Container = ({ children }: { children: ReactNode }) => (
<main className="mx-auto mt-[64px] px-4 md:px-10 lg:mt-[128px]">{children}</main>
Expand Down
4 changes: 0 additions & 4 deletions core/app/[locale]/not-found.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ const NotFoundQuery = graphql(
[HeaderFragment, FooterFragment, ProductCardFragment],
);

export const metadata = {
title: 'Not Found',
};

export default async function NotFound() {
const t = await getTranslations('NotFound');

Expand Down
10 changes: 7 additions & 3 deletions core/app/[locale]/store-selector/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ const StoreSelectorPageQuery = graphql(
[StoreLogoFragment],
);

export const metadata = {
title: 'Location selector',
};
export async function generateMetadata() {
const t = await getTranslations('StoreSelector');

return {
title: t('title'),
};
}

interface Props {
params: { locale: LocaleType };
Expand Down
Loading

0 comments on commit d032e65

Please sign in to comment.