Skip to content

Commit

Permalink
Fix locale issue (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
soniaklimas authored and karolkarolka committed Dec 4, 2024
1 parent 8c8dec3 commit 1e4e567
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
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

0 comments on commit 1e4e567

Please sign in to comment.