Skip to content

Commit 1a4896a

Browse files
committed
introduce vercel next-international implementation
1 parent c30bec3 commit 1a4896a

File tree

10 files changed

+25729
-7666
lines changed

10 files changed

+25729
-7666
lines changed

next-international.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// https://next-international.vercel.app/docs/app-setup
2+
// locales/index.ts
3+
import { createI18n } from 'next-international'
4+
5+
export const { useI18n, useScopedI18n, I18nProvider, getLocaleProps } = createI18n({
6+
hu: () => import('./hu'),
7+
en: () => import('./en')
8+
})

package-lock.json

Lines changed: 14313 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"lodash": "^4.17.21",
3939
"medusa-react": "^9.0.0",
4040
"next": "^14.0.0",
41+
"next-international": "^1.2.4",
4142
"pg": "^8.11.3",
4243
"react": "^18.2.0",
4344
"react-country-flag": "^3.0.2",

src/locales/client.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// https://next-international.vercel.app/docs/app-setup
2+
// locales/client.ts
3+
"use client"
4+
import { createI18nClient } from 'next-international/client'
5+
6+
export const { useI18n, useScopedI18n, I18nProviderClient } = createI18nClient({
7+
us: () => import('./us'),
8+
hu: () => import('./hu')
9+
})

src/locales/hu.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export default {
2+
"generic.somethingwrong": "Hiba történt",
3+
"nav.title": "Üzlet",
4+
hello: "Hello",
5+
welcome: "Hello {name}!",
6+
"about.you": "Hello {name}! You have {age} yo",
7+
"scope.test": "A scope",
8+
"scope.more.test": "A scope",
9+
"scope.more.param": "A scope with {param}",
10+
"scope.more.and.more.test": "A scope",
11+
"scope.more.stars#one": "1 star on GitHub",
12+
"scope.more.stars#other": "{count} stars on GitHub",
13+
"missing.translation.in.fr": "This should work",
14+
"cows#one": "A cow",
15+
"cows#other": "{count} cows",
16+
} as const

src/locales/server.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// https://next-international.vercel.app/docs/app-setup
2+
// locales/server.ts
3+
import { createI18nServer } from 'next-international/server'
4+
5+
export const { getI18n, getScopedI18n, getStaticParams } = createI18nServer({
6+
us: () => import('./us'),
7+
hu: () => import('./hu')
8+
})

src/locales/us.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export default {
2+
"generic.somethingwrong": "Something went wrong",
3+
"nav.title": "Store",
4+
hello: "Hello",
5+
welcome: "Hello {name}!",
6+
"about.you": "Hello {name}! You have {age} yo",
7+
"scope.test": "A scope",
8+
"scope.more.test": "A scope",
9+
"scope.more.param": "A scope with {param}",
10+
"scope.more.and.more.test": "A scope",
11+
"scope.more.stars#one": "1 star on GitHub",
12+
"scope.more.stars#other": "{count} stars on GitHub",
13+
"missing.translation.in.fr": "This should work",
14+
"cows#one": "A cow",
15+
"cows#other": "{count} cows",
16+
} as const

src/middleware.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Region } from "@medusajs/medusa"
22
import { notFound } from "next/navigation"
3+
import { createI18nMiddleware } from 'next-international/middleware'
34
import { NextRequest, NextResponse } from "next/server"
45

56
const BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
@@ -10,6 +11,11 @@ const regionMapCache = {
1011
regionMapUpdated: Date.now(),
1112
}
1213

14+
const I18nMiddleware = createI18nMiddleware({
15+
locales: ['us', 'hu'],
16+
defaultLocale: 'us',
17+
})
18+
1319
async function getRegionMap() {
1420
const { regionMap, regionMapUpdated } = regionMapCache
1521

@@ -104,7 +110,7 @@ export async function middleware(request: NextRequest) {
104110
(!isOnboarding || onboardingCookie) &&
105111
(!cartId || cartIdCookie)
106112
) {
107-
return NextResponse.next()
113+
return I18nMiddleware(request)
108114
}
109115

110116
const redirectPath =

src/modules/layout/templates/nav/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Suspense } from "react"
22

3+
import { getI18n } from '../../../../locales/server'
34
import { listRegions } from "@lib/data"
45
import LocalizedClientLink from "@modules/common/components/localized-client-link"
56
import CartButton from "@modules/layout/components/cart-button"
@@ -8,6 +9,8 @@ import SideMenu from "@modules/layout/components/side-menu"
89
export default async function Nav() {
910
const regions = await listRegions().then((regions) => regions)
1011

12+
const t = await getI18n()
13+
1114
return (
1215
<div className="sticky top-0 inset-x-0 z-50 group">
1316
<header className="relative h-16 mx-auto border-b duration-200 bg-white border-ui-border-base">
@@ -24,7 +27,7 @@ export default async function Nav() {
2427
className="txt-compact-xlarge-plus hover:text-ui-fg-base uppercase"
2528
data-testid="nav-store-link"
2629
>
27-
Medusa Store
30+
{t("nav.title")}
2831
</LocalizedClientLink>
2932
</div>
3033

0 commit comments

Comments
 (0)