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

refactor(core): localization #1316

Merged
merged 30 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
826f855
refactor: home
jorgemoya Aug 28, 2024
c0c9b37
refactor: StoreSelector
jorgemoya Aug 28, 2024
25445b0
refactor: maintenance
jorgemoya Aug 28, 2024
f8e4f6b
refactor: NotFound
jorgemoya Aug 28, 2024
c7a945a
refactor: Error
jorgemoya Aug 28, 2024
f3bf124
refactor: Blog
jorgemoya Aug 28, 2024
d0f2dcd
refactor: Compare
jorgemoya Aug 28, 2024
4fb873c
refactor: remove unused pagination translations
jorgemoya Aug 28, 2024
ab85635
refactor: Contact Us
jorgemoya Aug 28, 2024
7a223e5
refactor: Header
jorgemoya Aug 28, 2024
6048794
refactor: Product
jorgemoya Aug 28, 2024
27a973b
refactor: Login
jorgemoya Aug 29, 2024
2dcfaea
refactor: Account
jorgemoya Aug 29, 2024
c07b29a
refactor: reorder translations
jorgemoya Aug 29, 2024
f19275c
chore: update next-intl, update config, use single NextIntlClientProv…
jorgemoya Aug 29, 2024
824dc40
refactor: WebPages
jorgemoya Aug 29, 2024
ea82068
refactor: use shared hooks when necessary, remove locale from params
jorgemoya Aug 29, 2024
aa0270a
refactor: ProductCard
jorgemoya Aug 29, 2024
996eecc
refactor: CompareDrawer
jorgemoya Aug 29, 2024
c399967
refactor: Compare
jorgemoya Aug 29, 2024
8430f76
refactor: AddToCartButton
jorgemoya Aug 29, 2024
a003f2f
fix: refactor Compare
jorgemoya Aug 29, 2024
7c84212
chore: add changeset
jorgemoya Aug 29, 2024
87eecb6
fix: remove empty line in StoreSelector
jorgemoya Aug 29, 2024
23aa8a6
fix: add removed static declaration in StoreSelector
jorgemoya Aug 29, 2024
ed601c3
fix: add deleted runtime to NotFound
jorgemoya Aug 29, 2024
d1d0c46
fix: update docs to use correct hook
jorgemoya Aug 29, 2024
c90d007
fix: remove spacing in details
jorgemoya Aug 29, 2024
e529a7b
fix: add missing translation for prices in Compare page
jorgemoya Aug 29, 2024
dd0eeb7
fix: visual regression for label
jorgemoya Aug 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/forty-waves-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/catalyst-core": patch
---

Normalizes translations across all pages, updates the next-intl configuration, and simplifies translation handling in the project.
115 changes: 52 additions & 63 deletions core/app/[locale]/(default)/(faceted)/brand/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Metadata } from 'next';
import { notFound } from 'next/navigation';
import { NextIntlClientProvider } from 'next-intl';
import { getMessages, getTranslations, unstable_setRequestLocale } from 'next-intl/server';
import { getTranslations, unstable_setRequestLocale } from 'next-intl/server';

import { ProductCard } from '~/components/product-card';
import { Pagination } from '~/components/ui/pagination';
Expand Down Expand Up @@ -43,8 +42,7 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
export default async function Brand({ params: { slug, locale }, searchParams }: Props) {
unstable_setRequestLocale(locale);

const t = await getTranslations({ locale, namespace: 'Brand' });
const messages = await getMessages({ locale });
const t = await getTranslations('Brand');

const brandId = Number(slug);

Expand All @@ -63,70 +61,61 @@ export default async function Brand({ params: { slug, locale }, searchParams }:

return (
<div className="group">
<NextIntlClientProvider
locale={locale}
messages={{
FacetedGroup: messages.FacetedGroup ?? {},
Product: messages.Product ?? {},
AddToCart: messages.AddToCart ?? {},
}}
>
<div className="md:mb-8 lg:flex lg:flex-row lg:items-center lg:justify-between">
<h1 className="mb-4 text-4xl font-black lg:mb-0 lg:text-5xl">{brand.name}</h1>

<div className="flex flex-col items-center gap-3 whitespace-nowrap md:flex-row">
<MobileSideNav>
<FacetedSearch
facets={search.facets.items}
headingId="mobile-filter-heading"
pageType="brand"
/>
</MobileSideNav>
<div className="flex w-full flex-col items-start gap-4 md:flex-row md:items-center md:justify-end md:gap-6">
<SortBy />
<div className="order-3 py-4 text-base font-semibold md:order-2 md:py-0">
{t('sortBy', { items: productsCollection.collectionInfo?.totalItems ?? 0 })}
</div>
<div className="md:mb-8 lg:flex lg:flex-row lg:items-center lg:justify-between">
<h1 className="mb-4 text-4xl font-black lg:mb-0 lg:text-5xl">{brand.name}</h1>

<div className="flex flex-col items-center gap-3 whitespace-nowrap md:flex-row">
<MobileSideNav>
<FacetedSearch
facets={search.facets.items}
headingId="mobile-filter-heading"
pageType="brand"
/>
</MobileSideNav>
<div className="flex w-full flex-col items-start gap-4 md:flex-row md:items-center md:justify-end md:gap-6">
<SortBy />
<div className="order-3 py-4 text-base font-semibold md:order-2 md:py-0">
{t('sortBy', { items: productsCollection.collectionInfo?.totalItems ?? 0 })}
</div>
</div>
</div>
</div>

<div className="grid grid-cols-4 gap-8">
<FacetedSearch
className="mb-8 hidden lg:block"
facets={search.facets.items}
headingId="desktop-filter-heading"
pageType="brand"
/>

<section
aria-labelledby="product-heading"
className="col-span-4 group-has-[[data-pending]]:animate-pulse lg:col-span-3"
>
<h2 className="sr-only" id="product-heading">
{t('products')}
</h2>

<div className="grid grid-cols-2 gap-6 sm:grid-cols-3 sm:gap-8">
{products.map((product, index) => (
<ProductCard
imagePriority={index <= 3}
imageSize="wide"
key={product.entityId}
product={product}
/>
))}
</div>

<div className="grid grid-cols-4 gap-8">
<FacetedSearch
className="mb-8 hidden lg:block"
facets={search.facets.items}
headingId="desktop-filter-heading"
pageType="brand"
<Pagination
endCursor={endCursor ?? undefined}
hasNextPage={hasNextPage}
hasPreviousPage={hasPreviousPage}
startCursor={startCursor ?? undefined}
/>

<section
aria-labelledby="product-heading"
className="col-span-4 group-has-[[data-pending]]:animate-pulse lg:col-span-3"
>
<h2 className="sr-only" id="product-heading">
{t('products')}
</h2>

<div className="grid grid-cols-2 gap-6 sm:grid-cols-3 sm:gap-8">
{products.map((product, index) => (
<ProductCard
imagePriority={index <= 3}
imageSize="wide"
key={product.entityId}
product={product}
/>
))}
</div>

<Pagination
endCursor={endCursor ?? undefined}
hasNextPage={hasNextPage}
hasPreviousPage={hasPreviousPage}
startCursor={startCursor ?? undefined}
/>
</section>
</div>
</NextIntlClientProvider>
</section>
</div>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getTranslations } from 'next-intl/server';
import { useTranslations } from 'next-intl';

import { FragmentOf, graphql } from '~/client/graphql';
import { Link } from '~/components/link';
Expand Down Expand Up @@ -30,8 +30,8 @@ interface Props {
categoryTree: CategoryTree;
}

export async function SubCategories({ categoryTree }: Props) {
const t = await getTranslations('FacetedGroup.MobileSideNav');
export function SubCategories({ categoryTree }: Props) {
const t = useTranslations('FacetedGroup.MobileSideNav');

if (!categoryTree[0]?.children?.length) {
return null;
Expand Down
125 changes: 57 additions & 68 deletions core/app/[locale]/(default)/(faceted)/category/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Metadata } from 'next';
import { notFound } from 'next/navigation';
import { NextIntlClientProvider } from 'next-intl';
import { getMessages, getTranslations, unstable_setRequestLocale } from 'next-intl/server';
import { getTranslations, unstable_setRequestLocale } from 'next-intl/server';

import { Breadcrumbs } from '~/components/breadcrumbs';
import { ProductCard } from '~/components/product-card';
Expand Down Expand Up @@ -50,8 +49,7 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
export default async function Category({ params: { locale, slug }, searchParams }: Props) {
unstable_setRequestLocale(locale);

const t = await getTranslations({ locale, namespace: 'Category' });
const messages = await getMessages({ locale });
const t = await getTranslations('Category');

const categoryId = Number(slug);

Expand All @@ -71,74 +69,65 @@ export default async function Category({ params: { locale, slug }, searchParams
return (
<div className="group">
<Breadcrumbs category={category} />
<NextIntlClientProvider
locale={locale}
messages={{
FacetedGroup: messages.FacetedGroup ?? {},
Product: messages.Product ?? {},
AddToCart: messages.AddToCart ?? {},
}}
>
<div className="md:mb-8 lg:flex lg:flex-row lg:items-center lg:justify-between">
<h1 className="mb-4 text-4xl font-black lg:mb-0 lg:text-5xl">{category.name}</h1>

<div className="flex flex-col items-center gap-3 whitespace-nowrap md:flex-row">
<MobileSideNav>
<FacetedSearch
facets={search.facets.items}
headingId="mobile-filter-heading"
pageType="category"
>
<SubCategories categoryTree={categoryTree} />
</FacetedSearch>
</MobileSideNav>
<div className="flex w-full flex-col items-start gap-4 md:flex-row md:items-center md:justify-end md:gap-6">
<SortBy />
<div className="order-3 py-4 text-base font-semibold md:order-2 md:py-0">
{t('sortBy', { items: productsCollection.collectionInfo?.totalItems ?? 0 })}
</div>
<div className="md:mb-8 lg:flex lg:flex-row lg:items-center lg:justify-between">
<h1 className="mb-4 text-4xl font-black lg:mb-0 lg:text-5xl">{category.name}</h1>

<div className="flex flex-col items-center gap-3 whitespace-nowrap md:flex-row">
<MobileSideNav>
<FacetedSearch
facets={search.facets.items}
headingId="mobile-filter-heading"
pageType="category"
>
<SubCategories categoryTree={categoryTree} />
</FacetedSearch>
</MobileSideNav>
<div className="flex w-full flex-col items-start gap-4 md:flex-row md:items-center md:justify-end md:gap-6">
<SortBy />
<div className="order-3 py-4 text-base font-semibold md:order-2 md:py-0">
{t('sortBy', { items: productsCollection.collectionInfo?.totalItems ?? 0 })}
</div>
</div>
</div>
</div>

<div className="grid grid-cols-4 gap-8">
<FacetedSearch
className="mb-8 hidden lg:block"
facets={search.facets.items}
headingId="desktop-filter-heading"
pageType="category"
>
<SubCategories categoryTree={categoryTree} />
</FacetedSearch>

<section
aria-labelledby="product-heading"
className="col-span-4 group-has-[[data-pending]]:animate-pulse lg:col-span-3"
>
<h2 className="sr-only" id="product-heading">
{t('products')}
</h2>

<div className="grid grid-cols-2 gap-6 sm:grid-cols-3 sm:gap-8">
{products.map((product, index) => (
<ProductCard
imagePriority={index <= 3}
imageSize="wide"
key={product.entityId}
product={product}
/>
))}
</div>

<div className="grid grid-cols-4 gap-8">
<FacetedSearch
className="mb-8 hidden lg:block"
facets={search.facets.items}
headingId="desktop-filter-heading"
pageType="category"
>
<SubCategories categoryTree={categoryTree} />
</FacetedSearch>

<section
aria-labelledby="product-heading"
className="col-span-4 group-has-[[data-pending]]:animate-pulse lg:col-span-3"
>
<h2 className="sr-only" id="product-heading">
{t('products')}
</h2>

<div className="grid grid-cols-2 gap-6 sm:grid-cols-3 sm:gap-8">
{products.map((product, index) => (
<ProductCard
imagePriority={index <= 3}
imageSize="wide"
key={product.entityId}
product={product}
/>
))}
</div>

<Pagination
endCursor={endCursor ?? undefined}
hasNextPage={hasNextPage}
hasPreviousPage={hasPreviousPage}
startCursor={startCursor ?? undefined}
/>
</section>
</div>
</NextIntlClientProvider>
<Pagination
endCursor={endCursor ?? undefined}
hasNextPage={hasNextPage}
hasPreviousPage={hasPreviousPage}
startCursor={startCursor ?? undefined}
/>
</section>
</div>
<CategoryViewed category={category} categoryId={categoryId} products={products} />
</div>
);
Expand Down
Loading
Loading