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

Fix locale issue #69

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const HeroBanner = async ({

const header = fieldsMap["homepage-banner-header"]?.text;
const buttonText = fieldsMap["homepage-banner-button-text"]?.text;
const image = fieldsMap["homepage-banner-image-test"]?.imageUrl;
const image = fieldsMap["homepage-banner-image"]?.imageUrl;

return (
<div className="mb-14 flex flex-col items-center bg-stone-100 sm:h-[27rem] sm:flex-row">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const ProductsGrid = async ({

const header = fieldsMap["homepage-grid-item-header"]?.text;
const subheader = fieldsMap["homepage-grid-item-subheader"]?.text;
const image = fieldsMap["homepage-grid-item-image-test"]?.imageUrl;
const image = fieldsMap["homepage-grid-item-image"]?.imageUrl;
const buttonText = fieldsMap["homepage-button-text"]?.text;
const headerFontColor =
fieldsMap["homepage-grid-item-header-font-color"]?.text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@ import type { ButterCMSMenuServiceConfig } from "../types";
export const butterCMSMenuGetInfra =
({ token }: ButterCMSMenuServiceConfig): CMSMenuGetInfra =>
async ({ languageCode, slug }) => {
const locale = languageCode ? convertLanguageCode(languageCode) : undefined;

// @ts-expect-error due to deep type inference issues with ButterCMS types
const menu = await Butter(token).content.retrieve(
["navigation_menu"],
locale ? { locale } : undefined,
);
const locale = convertLanguageCode(languageCode);
let menu;

try {
// @ts-expect-error due to deep type inference issues with ButterCMS types
menu = await Butter(token).content.retrieve(
["navigation_menu"],
locale ? { locale } : undefined,
);
} catch (error) {
// Fallback to 'EN_US' if the initial request fails
menu = await Butter(token).content.retrieve(["navigation_menu"], {
locale: "enus",
});
}

if (!menu?.data?.data?.navigation_menu) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,18 @@ export const butterCMSPageGetInfra =
async ({ pageType, slug, languageCode }) => {
const resolvedPageType = pageType ?? PageType.STATIC_PAGE;
const locale = convertLanguageCode(languageCode);
const page = await Butter(token).page.retrieve(resolvedPageType, slug, {
locale,
} as PageRetrieveParams);
let page;

try {
page = await Butter(token).page.retrieve(resolvedPageType, slug, {
locale,
} as PageRetrieveParams);
} catch (error) {
// Fallback to 'EN_US' if the initial request fails
page = await Butter(token).page.retrieve(resolvedPageType, slug, {
locale: "enus",
} as PageRetrieveParams);
}

if (!page?.data?.data) {
return null;
Expand Down