- )
-}
diff --git a/src/app/[countryCode]/(checkout)/checkout/page.tsx b/src/app/[locale]/[countryCode]/(checkout)/checkout/page.tsx
similarity index 63%
rename from src/app/[countryCode]/(checkout)/checkout/page.tsx
rename to src/app/[locale]/[countryCode]/(checkout)/checkout/page.tsx
index 6244a1d06..2127914b8 100644
--- a/src/app/[countryCode]/(checkout)/checkout/page.tsx
+++ b/src/app/[locale]/[countryCode]/(checkout)/checkout/page.tsx
@@ -5,6 +5,8 @@ import CheckoutForm from "@modules/checkout/templates/checkout-form"
import CheckoutSummary from "@modules/checkout/templates/checkout-summary"
import { Metadata } from "next"
import { notFound } from "next/navigation"
+import { Suspense } from "react"
+
export const metadata: Metadata = {
title: "Checkout",
@@ -20,11 +22,13 @@ export default async function Checkout() {
const customer = await retrieveCustomer()
return (
-
-
-
-
-
-
+ >}>
+
+
+
+
+
+
+
)
}
diff --git a/src/app/[locale]/[countryCode]/(checkout)/layout.tsx b/src/app/[locale]/[countryCode]/(checkout)/layout.tsx
new file mode 100644
index 000000000..1880a7abe
--- /dev/null
+++ b/src/app/[locale]/[countryCode]/(checkout)/layout.tsx
@@ -0,0 +1,49 @@
+import { getTranslations } from "next-intl/server"
+import LocalizedClientLink from "@modules/common/components/localized-client-link"
+import ChevronDown from "@modules/common/icons/chevron-down"
+import MedusaCTA from "@modules/layout/components/medusa-cta"
+import { Suspense } from "react"
+
+export default async function CheckoutLayout({
+ children,
+}: {
+ children: React.ReactNode
+ params: { locale: string }
+}) {
+ const t = await getTranslations()
+ return (
+ >}>
+
+
+
+
+
{children}
+
+
+
+
+
+ )
+}
diff --git a/src/app/[countryCode]/(checkout)/not-found.tsx b/src/app/[locale]/[countryCode]/(checkout)/not-found.tsx
similarity index 60%
rename from src/app/[countryCode]/(checkout)/not-found.tsx
rename to src/app/[locale]/[countryCode]/(checkout)/not-found.tsx
index 838c9683e..e552be611 100644
--- a/src/app/[countryCode]/(checkout)/not-found.tsx
+++ b/src/app/[locale]/[countryCode]/(checkout)/not-found.tsx
@@ -1,3 +1,4 @@
+import { getTranslations } from "next-intl/server"
import InteractiveLink from "@modules/common/components/interactive-link"
import { Metadata } from "next"
@@ -7,13 +8,15 @@ export const metadata: Metadata = {
}
export default async function NotFound() {
+ const t = await getTranslations()
+
return (
-
Page not found
+
{t('PAGE_NOT_FOUND')}
- The page you tried to access does not exist.
+ {t('THE_PAGE_YOU_TRIED_TO_ACCESS_D')}
- Go to frontpage
+ {t('GO_TO_FRONTPAGE')}
)
}
diff --git a/src/app/[countryCode]/(main)/account/@dashboard/addresses/page.tsx b/src/app/[locale]/[countryCode]/(main)/account/@dashboard/addresses/page.tsx
similarity index 80%
rename from src/app/[countryCode]/(main)/account/@dashboard/addresses/page.tsx
rename to src/app/[locale]/[countryCode]/(main)/account/@dashboard/addresses/page.tsx
index 18e68651b..498d93a5c 100644
--- a/src/app/[countryCode]/(main)/account/@dashboard/addresses/page.tsx
+++ b/src/app/[locale]/[countryCode]/(main)/account/@dashboard/addresses/page.tsx
@@ -1,3 +1,5 @@
+import { getTranslations } from "next-intl/server"
+
import { Metadata } from "next"
import { notFound } from "next/navigation"
@@ -18,6 +20,7 @@ export default async function Addresses(props: {
const { countryCode } = params
const customer = await retrieveCustomer()
const region = await getRegion(countryCode)
+ const t = await getTranslations()
if (!customer || !region) {
notFound()
@@ -26,10 +29,9 @@ export default async function Addresses(props: {
return (
-
Shipping Addresses
+
{t('SHIPPING_ADDRESSES')}
- View and update your shipping addresses, you can add as many as you
- like. Saving your addresses will make them available during checkout.
+ {t('VIEW_AND_UPDATE_YOUR_SHIPPING')}
diff --git a/src/app/[countryCode]/(main)/account/@dashboard/loading.tsx b/src/app/[locale]/[countryCode]/(main)/account/@dashboard/loading.tsx
similarity index 100%
rename from src/app/[countryCode]/(main)/account/@dashboard/loading.tsx
rename to src/app/[locale]/[countryCode]/(main)/account/@dashboard/loading.tsx
diff --git a/src/app/[countryCode]/(main)/account/@dashboard/orders/details/[id]/page.tsx b/src/app/[locale]/[countryCode]/(main)/account/@dashboard/orders/details/[id]/page.tsx
similarity index 79%
rename from src/app/[countryCode]/(main)/account/@dashboard/orders/details/[id]/page.tsx
rename to src/app/[locale]/[countryCode]/(main)/account/@dashboard/orders/details/[id]/page.tsx
index bd158c994..fc656e60c 100644
--- a/src/app/[countryCode]/(main)/account/@dashboard/orders/details/[id]/page.tsx
+++ b/src/app/[locale]/[countryCode]/(main)/account/@dashboard/orders/details/[id]/page.tsx
@@ -1,3 +1,5 @@
+import { getTranslations } from "next-intl/server"
+
import { retrieveOrder } from "@lib/data/orders"
import OrderDetailsTemplate from "@modules/order/templates/order-details-template"
import { Metadata } from "next"
@@ -8,16 +10,19 @@ type Props = {
}
export async function generateMetadata(props: Props): Promise {
+
+ const t = await getTranslations()
+
const params = await props.params
const order = await retrieveOrder(params.id).catch(() => null)
if (!order) {
notFound()
}
-
+
return {
- title: `Order #${order.display_id}`,
- description: `View your order`,
+ title: `${t('ORDER')} #${order.display_id}`,
+ description: `${t('VIEW_YOUR_ORDER')}`,
}
}
diff --git a/src/app/[countryCode]/(main)/account/@dashboard/orders/page.tsx b/src/app/[locale]/[countryCode]/(main)/account/@dashboard/orders/page.tsx
similarity index 82%
rename from src/app/[countryCode]/(main)/account/@dashboard/orders/page.tsx
rename to src/app/[locale]/[countryCode]/(main)/account/@dashboard/orders/page.tsx
index 5d65e32bd..cd6673bff 100644
--- a/src/app/[countryCode]/(main)/account/@dashboard/orders/page.tsx
+++ b/src/app/[locale]/[countryCode]/(main)/account/@dashboard/orders/page.tsx
@@ -1,3 +1,4 @@
+import { getTranslations } from "next-intl/server"
import { Metadata } from "next"
import OrderOverview from "@modules/account/components/order-overview"
@@ -13,6 +14,7 @@ export const metadata: Metadata = {
export default async function Orders() {
const orders = await listOrders()
+ const t = await getTranslations()
if (!orders) {
notFound()
@@ -21,10 +23,9 @@ export default async function Orders() {
return (
-
Orders
+
{t('ORDERS')}
- View your previous orders and their status. You can also create
- returns or exchanges for your orders if needed.
+ {t('VIEW_YOUR_PREVIOUS_ORDERS_AND')}
diff --git a/src/app/[countryCode]/(main)/account/@dashboard/page.tsx b/src/app/[locale]/[countryCode]/(main)/account/@dashboard/page.tsx
similarity index 100%
rename from src/app/[countryCode]/(main)/account/@dashboard/page.tsx
rename to src/app/[locale]/[countryCode]/(main)/account/@dashboard/page.tsx
diff --git a/src/app/[countryCode]/(main)/account/@dashboard/profile/page.tsx b/src/app/[locale]/[countryCode]/(main)/account/@dashboard/profile/page.tsx
similarity index 86%
rename from src/app/[countryCode]/(main)/account/@dashboard/profile/page.tsx
rename to src/app/[locale]/[countryCode]/(main)/account/@dashboard/profile/page.tsx
index 97b05808c..887542dec 100644
--- a/src/app/[countryCode]/(main)/account/@dashboard/profile/page.tsx
+++ b/src/app/[locale]/[countryCode]/(main)/account/@dashboard/profile/page.tsx
@@ -1,3 +1,5 @@
+import { getTranslations } from "next-intl/server"
+
import { Metadata } from "next"
import ProfilePhone from "@modules/account//components/profile-phone"
@@ -18,6 +20,7 @@ export const metadata: Metadata = {
export default async function Profile() {
const customer = await retrieveCustomer()
const regions = await listRegions()
+ const t = await getTranslations()
if (!customer || !regions) {
notFound()
@@ -26,11 +29,9 @@ export default async function Profile() {
return (
-
Profile
+
{t('PROFILE')}
- View and update your profile information, including your name, email,
- and phone number. You can also update your billing address, or change
- your password.
+ {t('VIEW_AND_UPDATE_YOUR_PROFILE_I')}
diff --git a/src/app/[countryCode]/(main)/account/@login/page.tsx b/src/app/[locale]/[countryCode]/(main)/account/@login/page.tsx
similarity index 100%
rename from src/app/[countryCode]/(main)/account/@login/page.tsx
rename to src/app/[locale]/[countryCode]/(main)/account/@login/page.tsx
diff --git a/src/app/[countryCode]/(main)/account/layout.tsx b/src/app/[locale]/[countryCode]/(main)/account/layout.tsx
similarity index 100%
rename from src/app/[countryCode]/(main)/account/layout.tsx
rename to src/app/[locale]/[countryCode]/(main)/account/layout.tsx
diff --git a/src/app/[countryCode]/(main)/account/loading.tsx b/src/app/[locale]/[countryCode]/(main)/account/loading.tsx
similarity index 100%
rename from src/app/[countryCode]/(main)/account/loading.tsx
rename to src/app/[locale]/[countryCode]/(main)/account/loading.tsx
diff --git a/src/app/[countryCode]/(main)/cart/loading.tsx b/src/app/[locale]/[countryCode]/(main)/cart/loading.tsx
similarity index 100%
rename from src/app/[countryCode]/(main)/cart/loading.tsx
rename to src/app/[locale]/[countryCode]/(main)/cart/loading.tsx
diff --git a/src/app/[countryCode]/(main)/cart/not-found.tsx b/src/app/[locale]/[countryCode]/(main)/cart/not-found.tsx
similarity index 60%
rename from src/app/[countryCode]/(main)/cart/not-found.tsx
rename to src/app/[locale]/[countryCode]/(main)/cart/not-found.tsx
index 91af293ef..128c9ae3d 100644
--- a/src/app/[countryCode]/(main)/cart/not-found.tsx
+++ b/src/app/[locale]/[countryCode]/(main)/cart/not-found.tsx
@@ -1,3 +1,5 @@
+import { useTranslations } from "next-intl"
+
import { Metadata } from "next"
import InteractiveLink from "@modules/common/components/interactive-link"
@@ -8,14 +10,14 @@ export const metadata: Metadata = {
}
export default function NotFound() {
+ const t = useTranslations()
return (
-
Page not found
+
{t('PAGE_NOT_FOUND')}
- The cart you tried to access does not exist. Clear your cookies and try
- again.
+ {t('THE_CART_YOU_TRIED_TO_ACCESS_D')}
- Go to frontpage
+ {t('GO_TO_FRONTPAGE')}
)
}
diff --git a/src/app/[countryCode]/(main)/cart/page.tsx b/src/app/[locale]/[countryCode]/(main)/cart/page.tsx
similarity index 100%
rename from src/app/[countryCode]/(main)/cart/page.tsx
rename to src/app/[locale]/[countryCode]/(main)/cart/page.tsx
diff --git a/src/app/[countryCode]/(main)/categories/[...category]/page.tsx b/src/app/[locale]/[countryCode]/(main)/categories/[...category]/page.tsx
similarity index 92%
rename from src/app/[countryCode]/(main)/categories/[...category]/page.tsx
rename to src/app/[locale]/[countryCode]/(main)/categories/[...category]/page.tsx
index bd851b729..683521ecf 100644
--- a/src/app/[countryCode]/(main)/categories/[...category]/page.tsx
+++ b/src/app/[locale]/[countryCode]/(main)/categories/[...category]/page.tsx
@@ -6,9 +6,10 @@ import { listRegions } from "@lib/data/regions"
import { StoreRegion } from "@medusajs/types"
import CategoryTemplate from "@modules/categories/templates"
import { SortOptions } from "@modules/store/components/refinement-list/sort-products"
+import { setRequestLocale } from "next-intl/server"
type Props = {
- params: Promise<{ category: string[]; countryCode: string }>
+ params: Promise<{ category: string[]; countryCode: string; locale: string }>
searchParams: Promise<{
sortBy?: SortOptions
page?: string
@@ -66,6 +67,7 @@ export async function generateMetadata(props: Props): Promise {
export default async function CategoryPage(props: Props) {
const searchParams = await props.searchParams
const params = await props.params
+ setRequestLocale(params.locale)
const { sortBy, page } = searchParams
const productCategory = await getCategoryByHandle(params.category)
diff --git a/src/app/[countryCode]/(main)/collections/[handle]/page.tsx b/src/app/[locale]/[countryCode]/(main)/collections/[handle]/page.tsx
similarity index 92%
rename from src/app/[countryCode]/(main)/collections/[handle]/page.tsx
rename to src/app/[locale]/[countryCode]/(main)/collections/[handle]/page.tsx
index ba237f17f..f8bbf56c4 100644
--- a/src/app/[countryCode]/(main)/collections/[handle]/page.tsx
+++ b/src/app/[locale]/[countryCode]/(main)/collections/[handle]/page.tsx
@@ -6,9 +6,10 @@ import { listRegions } from "@lib/data/regions"
import { StoreCollection, StoreRegion } from "@medusajs/types"
import CollectionTemplate from "@modules/collections/templates"
import { SortOptions } from "@modules/store/components/refinement-list/sort-products"
+import { setRequestLocale } from "next-intl/server"
type Props = {
- params: Promise<{ handle: string; countryCode: string }>
+ params: Promise<{ handle: string; countryCode: string; locale: string }>
searchParams: Promise<{
page?: string
sortBy?: SortOptions
@@ -70,6 +71,7 @@ export default async function CollectionPage(props: Props) {
const searchParams = await props.searchParams
const params = await props.params
const { sortBy, page } = searchParams
+ setRequestLocale(params.locale)
const collection = await getCollectionByHandle(params.handle).then(
(collection: StoreCollection) => collection
diff --git a/src/app/[countryCode]/(main)/layout.tsx b/src/app/[locale]/[countryCode]/(main)/layout.tsx
similarity index 100%
rename from src/app/[countryCode]/(main)/layout.tsx
rename to src/app/[locale]/[countryCode]/(main)/layout.tsx
diff --git a/src/app/[countryCode]/(main)/not-found.tsx b/src/app/[locale]/[countryCode]/(main)/not-found.tsx
similarity index 58%
rename from src/app/[countryCode]/(main)/not-found.tsx
rename to src/app/[locale]/[countryCode]/(main)/not-found.tsx
index d001053f7..b0cf26e45 100644
--- a/src/app/[countryCode]/(main)/not-found.tsx
+++ b/src/app/[locale]/[countryCode]/(main)/not-found.tsx
@@ -1,20 +1,26 @@
+"use client"
+
import { Metadata } from "next"
import InteractiveLink from "@modules/common/components/interactive-link"
+import { useTranslations } from "next-intl"
export const metadata: Metadata = {
title: "404",
description: "Something went wrong",
}
+
export default function NotFound() {
+ const t = useTranslations()
+
return (
-
Page not found
+
{t('PAGE_NOT_FOUND')}
- The page you tried to access does not exist.
+ {t('THE_PAGE_YOU_TRIED_TO_ACCESS_D') as string}
- Go to frontpage
+ {t('GO_TO_FRONTPAGE')}
)
}
diff --git a/src/app/[countryCode]/(main)/order/[id]/confirmed/loading.tsx b/src/app/[locale]/[countryCode]/(main)/order/[id]/confirmed/loading.tsx
similarity index 100%
rename from src/app/[countryCode]/(main)/order/[id]/confirmed/loading.tsx
rename to src/app/[locale]/[countryCode]/(main)/order/[id]/confirmed/loading.tsx
diff --git a/src/app/[countryCode]/(main)/order/[id]/confirmed/page.tsx b/src/app/[locale]/[countryCode]/(main)/order/[id]/confirmed/page.tsx
similarity index 100%
rename from src/app/[countryCode]/(main)/order/[id]/confirmed/page.tsx
rename to src/app/[locale]/[countryCode]/(main)/order/[id]/confirmed/page.tsx
diff --git a/src/app/[countryCode]/(main)/order/[id]/transfer/[token]/accept/page.tsx b/src/app/[locale]/[countryCode]/(main)/order/[id]/transfer/[token]/accept/page.tsx
similarity index 100%
rename from src/app/[countryCode]/(main)/order/[id]/transfer/[token]/accept/page.tsx
rename to src/app/[locale]/[countryCode]/(main)/order/[id]/transfer/[token]/accept/page.tsx
diff --git a/src/app/[countryCode]/(main)/order/[id]/transfer/[token]/decline/page.tsx b/src/app/[locale]/[countryCode]/(main)/order/[id]/transfer/[token]/decline/page.tsx
similarity index 100%
rename from src/app/[countryCode]/(main)/order/[id]/transfer/[token]/decline/page.tsx
rename to src/app/[locale]/[countryCode]/(main)/order/[id]/transfer/[token]/decline/page.tsx
diff --git a/src/app/[countryCode]/(main)/order/[id]/transfer/[token]/page.tsx b/src/app/[locale]/[countryCode]/(main)/order/[id]/transfer/[token]/page.tsx
similarity index 100%
rename from src/app/[countryCode]/(main)/order/[id]/transfer/[token]/page.tsx
rename to src/app/[locale]/[countryCode]/(main)/order/[id]/transfer/[token]/page.tsx
diff --git a/src/app/[countryCode]/(main)/page.tsx b/src/app/[locale]/[countryCode]/(main)/page.tsx
similarity index 100%
rename from src/app/[countryCode]/(main)/page.tsx
rename to src/app/[locale]/[countryCode]/(main)/page.tsx
diff --git a/src/app/[countryCode]/(main)/products/[handle]/page.tsx b/src/app/[locale]/[countryCode]/(main)/products/[handle]/page.tsx
similarity index 93%
rename from src/app/[countryCode]/(main)/products/[handle]/page.tsx
rename to src/app/[locale]/[countryCode]/(main)/products/[handle]/page.tsx
index c2615ff07..f48882930 100644
--- a/src/app/[countryCode]/(main)/products/[handle]/page.tsx
+++ b/src/app/[locale]/[countryCode]/(main)/products/[handle]/page.tsx
@@ -3,9 +3,11 @@ import { notFound } from "next/navigation"
import { listProducts } from "@lib/data/products"
import { getRegion, listRegions } from "@lib/data/regions"
import ProductTemplate from "@modules/products/templates"
+import { setRequestLocale } from "next-intl/server"
+
type Props = {
- params: Promise<{ countryCode: string; handle: string }>
+ params: Promise<{ countryCode: string; handle: string; locale: string }>
}
export async function generateStaticParams() {
@@ -74,6 +76,7 @@ export async function generateMetadata(props: Props): Promise {
export default async function ProductPage(props: Props) {
const params = await props.params
const region = await getRegion(params.countryCode)
+ setRequestLocale(params.locale)
if (!region) {
notFound()
diff --git a/src/app/[countryCode]/(main)/store/page.tsx b/src/app/[locale]/[countryCode]/(main)/store/page.tsx
similarity index 100%
rename from src/app/[countryCode]/(main)/store/page.tsx
rename to src/app/[locale]/[countryCode]/(main)/store/page.tsx
diff --git a/src/app/layout.tsx b/src/app/layout.tsx
index 6db3994cf..0c209e865 100644
--- a/src/app/layout.tsx
+++ b/src/app/layout.tsx
@@ -1,17 +1,42 @@
import { getBaseURL } from "@lib/util/env"
+import { LOCALE_COOKIE, routing } from "@lib/i18n/settings";
import { Metadata } from "next"
+import { NextIntlClientProvider } from "next-intl"
+import { getLocale, getMessages } from 'next-intl/server';
+import { setRequestLocale } from "next-intl/server"
+import { cookies } from "next/headers"
+import { Suspense } from "react"
import "styles/globals.css"
export const metadata: Metadata = {
metadataBase: new URL(getBaseURL()),
+};
+
+export function generateStaticParams() {
+ return routing.locales.map((locale) => ({ locale }));
}
-export default function RootLayout(props: { children: React.ReactNode }) {
+export default async function RootLayout({
+ children,
+ params: { locale: requestedLocale },
+}: {
+ children: React.ReactNode;
+ params: { locale: string };
+}) {
+
+ // Set the request locale (for server-side context)
+ setRequestLocale(await getLocale());
+
+ const messages = await getMessages();
+
return (
-
-
- {props.children}
-
+
+ {/* Provide the intl context */}
+
+
+ {children}
+
+
- )
+ );
}
diff --git a/src/app/not-found.tsx b/src/app/not-found.tsx
index ece9db8db..571f7c88c 100644
--- a/src/app/not-found.tsx
+++ b/src/app/not-found.tsx
@@ -1,7 +1,8 @@
import { ArrowUpRightMini } from "@medusajs/icons"
import { Text } from "@medusajs/ui"
import { Metadata } from "next"
-import Link from "next/link"
+import { Link } from "@lib/i18n/navigation"
+import { useTranslations } from "next-intl"
export const metadata: Metadata = {
title: "404",
@@ -9,17 +10,19 @@ export const metadata: Metadata = {
}
export default function NotFound() {
+ const t = useTranslations()
+
return (
-
Page not found
+
{t('PAGE_NOT_FOUND')}
- The page you tried to access does not exist.
+ {t('THE_PAGE_YOU_TRIED_TO_ACCESS_D')}
- Go to frontpage
+ {t('GO_TO_FRONTPAGE')} }) => {
+ // resolve the locale asynchronously
+ const resolvedRequestLocale = (await requestLocale) || routing.defaultLocale;
+
+ // validate the locale and fallback if necessary
+ const resolvedLocale = routing.locales.includes(resolvedRequestLocale)
+ ? resolvedRequestLocale
+ : routing.defaultLocale;
+
+ const messages = (await import(`@locales/${resolvedLocale}/index.json`)).default;
+
+ return {
+ locale: resolvedLocale,
+ messages,
+ formats,
+ };
+});
+
+export default getI18NRequestConfig;
+
+
\ No newline at end of file
diff --git a/src/lib/i18n/settings.ts b/src/lib/i18n/settings.ts
new file mode 100644
index 000000000..96b7eab4b
--- /dev/null
+++ b/src/lib/i18n/settings.ts
@@ -0,0 +1,15 @@
+import { defineRouting } from 'next-intl/routing';
+
+export const fallbackLng = "en"
+export const languages = [
+ fallbackLng,
+ "ar"
+]
+export const localePrefix = "always"
+export const LOCALE_COOKIE = "NEXT_LOCALE"
+
+export const routing = defineRouting({
+ locales: languages,
+ defaultLocale: fallbackLng,
+ localeDetection: true,
+})
\ No newline at end of file
diff --git a/src/middleware.ts b/src/middleware.ts
index a6cb4e26d..d838d0c3f 100644
--- a/src/middleware.ts
+++ b/src/middleware.ts
@@ -1,6 +1,11 @@
import { HttpTypes } from "@medusajs/types"
import { NextRequest, NextResponse } from "next/server"
+import createIntlMiddleware from "next-intl/middleware"
+import { routing } from "./lib/i18n/settings";
+
+const intlMiddleware = createIntlMiddleware(routing)
+
const BACKEND_URL = process.env.MEDUSA_BACKEND_URL
const PUBLISHABLE_API_KEY = process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY
const DEFAULT_REGION = process.env.NEXT_PUBLIC_DEFAULT_REGION || "us"
@@ -69,7 +74,8 @@ async function getRegionMap(cacheId: string) {
*/
async function getCountryCode(
request: NextRequest,
- regionMap: Map
+ regionMap: Map,
+ countryCodePathnameIndex: number
) {
try {
let countryCode
@@ -78,7 +84,9 @@ async function getCountryCode(
.get("x-vercel-ip-country")
?.toLowerCase()
- const urlCountryCode = request.nextUrl.pathname.split("/")[1]?.toLowerCase()
+ const urlCountryCode = request.nextUrl.pathname
+ .split("/")
+ [countryCodePathnameIndex]?.toLowerCase()
if (urlCountryCode && regionMap.has(urlCountryCode)) {
countryCode = urlCountryCode
@@ -108,20 +116,51 @@ export async function middleware(request: NextRequest) {
let response = NextResponse.redirect(redirectUrl, 307)
- let cacheIdCookie = request.cookies.get("_medusa_cache_id")
+ const pathnameArr = request.nextUrl.pathname.split("/");
+ const urlHasKnownLocale = routing.locales.includes(pathnameArr[1]);
+
+ // need to redirect manually if we provide a wrong locale when a countryCode is included
+ const urlHasUnknownLocale =
+ !urlHasKnownLocale &&
+ pathnameArr?.[1]?.length == 2 &&
+ (pathnameArr?.[2] ? pathnameArr[2].length == 2 : true);
+
+
+ const redirectPath =
+ request.nextUrl.pathname === "/"
+ ? ""
+ : urlHasKnownLocale || urlHasUnknownLocale
+ ? pathnameArr.slice(2).join("/")
+ : request.nextUrl.pathname
+
+
+ const queryString = request.nextUrl.search ? request.nextUrl.search : ""
- let cacheId = cacheIdCookie?.value || crypto.randomUUID()
+ if (urlHasUnknownLocale) {
+ redirectUrl = `${request.nextUrl.origin}/${routing.defaultLocale}/${redirectPath}${queryString}`
+ response = NextResponse.redirect(`${redirectUrl}`, 307)
+ }
- const regionMap = await getRegionMap(cacheId)
+ let cacheIdCookie = request.cookies.get("_medusa_cache_id");
- const countryCode = regionMap && (await getCountryCode(request, regionMap))
+ let cacheId = cacheIdCookie?.value || crypto.randomUUID();
+
+ const regionMap = await getRegionMap(cacheId);
+
+ const countryCodePathnameIndex = urlHasKnownLocale ? 2 : 1;
+
+ const countryCode =
+ regionMap &&
+ (await getCountryCode(request, regionMap, countryCodePathnameIndex));
+
const urlHasCountryCode =
- countryCode && request.nextUrl.pathname.split("/")[1].includes(countryCode)
+ countryCode &&
+ request.nextUrl.pathname.split("/")[countryCodePathnameIndex] == countryCode
// if one of the country codes is in the url and the cache id is set, return next
- if (urlHasCountryCode && cacheIdCookie) {
- return NextResponse.next()
+ if (!urlHasUnknownLocale && urlHasCountryCode && cacheIdCookie) {
+ return intlMiddleware(request)
}
// if one of the country codes is in the url and the cache id is not set, set the cache id and redirect
@@ -138,14 +177,13 @@ export async function middleware(request: NextRequest) {
return NextResponse.next()
}
- const redirectPath =
- request.nextUrl.pathname === "/" ? "" : request.nextUrl.pathname
-
- const queryString = request.nextUrl.search ? request.nextUrl.search : ""
+ if (!urlHasKnownLocale) return intlMiddleware(request)
// If no country code is set, we redirect to the relevant region.
if (!urlHasCountryCode && countryCode) {
- redirectUrl = `${request.nextUrl.origin}/${countryCode}${redirectPath}${queryString}`
+ redirectUrl = `${request.nextUrl.origin}/${
+ urlHasKnownLocale ? pathnameArr[1] + "/" : ""
+ }${countryCode}/${redirectPath}${queryString}`
response = NextResponse.redirect(`${redirectUrl}`, 307)
}
diff --git a/src/modules/account/components/account-info/index.tsx b/src/modules/account/components/account-info/index.tsx
index f0c4937d8..d9c409536 100644
--- a/src/modules/account/components/account-info/index.tsx
+++ b/src/modules/account/components/account-info/index.tsx
@@ -1,3 +1,5 @@
+import { useTranslations } from "next-intl"
+
import { Disclosure } from "@headlessui/react"
import { Badge, Button, clx } from "@medusajs/ui"
import { useEffect } from "react"
@@ -41,6 +43,7 @@ const AccountInfo = ({
}
}, [isSuccess, close])
+ const t = useTranslations()
return (