Skip to content

Commit 133e5ca

Browse files
committed
setup next-intl files
1 parent a45bb78 commit 133e5ca

File tree

9 files changed

+143
-125
lines changed

9 files changed

+143
-125
lines changed

next-i18next.config.js

Lines changed: 0 additions & 32 deletions
This file was deleted.

next.config.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ const withBundleAnalyzer = require("@next/bundle-analyzer")({
55
enabled: process.env.ANALYZE === "true",
66
})
77

8-
const { i18n } = require("./next-i18next.config")
8+
const createNextIntlPlugin = require("next-intl/plugin")
9+
10+
const withNextIntl = createNextIntlPlugin()
911

1012
const LIMIT_CPUS = Number(process.env.LIMIT_CPUS ?? 2)
1113

@@ -59,7 +61,6 @@ module.exports = (phase, { defaultConfig }) => {
5961

6062
return config
6163
},
62-
i18n,
6364
trailingSlash: true,
6465
images: {
6566
deviceSizes: [640, 750, 828, 1080, 1200, 1504, 1920],
@@ -111,5 +112,5 @@ module.exports = (phase, { defaultConfig }) => {
111112
}
112113
}
113114

114-
return withBundleAnalyzer(nextConfig)
115+
return withBundleAnalyzer(withNextIntl(nextConfig))
115116
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"lodash.union": "^4.6.0",
7171
"next": "^14.2.21",
7272
"next-i18next": "^14.0.3",
73+
"next-intl": "^3.26.3",
7374
"next-mdx-remote": "^3.0.8",
7475
"next-sitemap": "^4.2.3",
7576
"next-themes": "^0.3.0",

src/i18n/request.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import createMiddleware from "next-intl/middleware"
2+
3+
import { LOCALES_CODES } from "@/lib/constants"
4+
5+
import { routing } from "./routing"
6+
7+
export default createMiddleware(routing)
8+
9+
export const config = {
10+
// Match only internationalized pathnames
11+
matcher: ["/", `/${LOCALES_CODES.join("|")}/:path*`],
12+
}

src/i18n/routing.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { createNavigation } from "next-intl/navigation"
2+
import { defineRouting } from "next-intl/routing"
3+
4+
import { DEFAULT_LOCALE, LOCALES_CODES } from "@/lib/constants"
5+
6+
export const routing = defineRouting({
7+
locales: LOCALES_CODES,
8+
defaultLocale: DEFAULT_LOCALE,
9+
})
10+
11+
// Lightweight wrappers around Next.js' navigation APIs
12+
// that will consider the routing configuration
13+
export const { Link, redirect, usePathname, useRouter, getPathname } =
14+
createNavigation(routing)

src/middleware.ts

Lines changed: 0 additions & 77 deletions
This file was deleted.

src/pages/_app.tsx

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { useEffect } from "react"
2+
import { useRouter } from "next/router"
23
import { appWithTranslation } from "next-i18next"
4+
import { NextIntlClientProvider } from "next-intl"
35
import { TooltipProvider } from "@radix-ui/react-tooltip"
46
import { init } from "@socialgouv/matomo-next"
57

@@ -12,6 +14,8 @@ import "@/styles/global.css"
1214
import { BaseLayout } from "@/layouts/BaseLayout"
1315

1416
const App = ({ Component, pageProps }: AppPropsWithLayout) => {
17+
const router = useRouter()
18+
1519
useEffect(() => {
1620
if (!process.env.IS_PREVIEW_DEPLOY) {
1721
init({
@@ -26,17 +30,23 @@ const App = ({ Component, pageProps }: AppPropsWithLayout) => {
2630
const getLayout = Component.getLayout ?? ((page) => page)
2731

2832
return (
29-
<ThemeProvider>
30-
<TooltipProvider>
31-
<BaseLayout
32-
contentIsOutdated={!!pageProps.frontmatter?.isOutdated}
33-
contentNotTranslated={pageProps.contentNotTranslated}
34-
lastDeployLocaleTimestamp={pageProps.lastDeployLocaleTimestamp}
35-
>
36-
{getLayout(<Component {...pageProps} />)}
37-
</BaseLayout>
38-
</TooltipProvider>
39-
</ThemeProvider>
33+
<NextIntlClientProvider
34+
locale={router.locale}
35+
timeZone="Europe/Vienna" // TODO: get from locale?
36+
messages={pageProps.messages}
37+
>
38+
<ThemeProvider>
39+
<TooltipProvider>
40+
<BaseLayout
41+
contentIsOutdated={!!pageProps.frontmatter?.isOutdated}
42+
contentNotTranslated={pageProps.contentNotTranslated}
43+
lastDeployLocaleTimestamp={pageProps.lastDeployLocaleTimestamp}
44+
>
45+
{getLayout(<Component {...pageProps} />)}
46+
</BaseLayout>
47+
</TooltipProvider>
48+
</ThemeProvider>
49+
</NextIntlClientProvider>
4050
)
4151
}
4252

src/pages/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Fragment, lazy, Suspense } from "react"
22
import type { GetStaticProps, InferGetStaticPropsType } from "next"
3-
import { serverSideTranslations } from "next-i18next/serverSideTranslations"
43
import { FaDiscord, FaGithub } from "react-icons/fa6"
54
import { IoMdCopy } from "react-icons/io"
65
import { MdCheck } from "react-icons/md"
@@ -186,7 +185,7 @@ export const getStaticProps = (async ({ locale }) => {
186185

187186
return {
188187
props: {
189-
...(await serverSideTranslations(locale!, requiredNamespaces)),
188+
messages: (await import(`../intl/${locale}/common.json`)).default,
190189
calendar,
191190
contentNotTranslated,
192191
lastDeployLocaleTimestamp,

yarn.lock

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3487,6 +3487,54 @@
34873487
resolved "https://registry.yarnpkg.com/@floating-ui/utils/-/utils-0.2.5.tgz#105c37d9d9620ce69b7f692a20c821bf1ad2cbf9"
34883488
integrity sha512-sTcG+QZ6fdEUObICavU+aB3Mp8HY4n14wYHdxK4fXjPmv3PXZZeY5RaguJmGyeH/CJQhX3fqKUtS4qc1LoHwhQ==
34893489

3490+
"@formatjs/[email protected]":
3491+
version "2.3.3"
3492+
resolved "https://registry.yarnpkg.com/@formatjs/ecma402-abstract/-/ecma402-abstract-2.3.3.tgz#fbc7555c9e4fdd104cd5e23129fa3735be3ad0ba"
3493+
integrity sha512-pJT1OkhplSmvvr6i3CWTPvC/FGC06MbN5TNBfRO6Ox62AEz90eMq+dVvtX9Bl3jxCEkS0tATzDarRZuOLw7oFg==
3494+
dependencies:
3495+
"@formatjs/fast-memoize" "2.2.6"
3496+
"@formatjs/intl-localematcher" "0.6.0"
3497+
decimal.js "10"
3498+
tslib "2"
3499+
3500+
"@formatjs/[email protected]", "@formatjs/fast-memoize@^2.2.0":
3501+
version "2.2.6"
3502+
resolved "https://registry.yarnpkg.com/@formatjs/fast-memoize/-/fast-memoize-2.2.6.tgz#fac0a84207a1396be1f1aa4ee2805b179e9343d1"
3503+
integrity sha512-luIXeE2LJbQnnzotY1f2U2m7xuQNj2DA8Vq4ce1BY9ebRZaoPB1+8eZ6nXpLzsxuW5spQxr7LdCg+CApZwkqkw==
3504+
dependencies:
3505+
tslib "2"
3506+
3507+
"@formatjs/[email protected]":
3508+
version "2.11.1"
3509+
resolved "https://registry.yarnpkg.com/@formatjs/icu-messageformat-parser/-/icu-messageformat-parser-2.11.1.tgz#59d69124b9cf3186800a576c0228947d10594347"
3510+
integrity sha512-o0AhSNaOfKoic0Sn1GkFCK4MxdRsw7mPJ5/rBpIqdvcC7MIuyUSW8WChUEvrK78HhNpYOgqCQbINxCTumJLzZA==
3511+
dependencies:
3512+
"@formatjs/ecma402-abstract" "2.3.3"
3513+
"@formatjs/icu-skeleton-parser" "1.8.13"
3514+
tslib "2"
3515+
3516+
"@formatjs/[email protected]":
3517+
version "1.8.13"
3518+
resolved "https://registry.yarnpkg.com/@formatjs/icu-skeleton-parser/-/icu-skeleton-parser-1.8.13.tgz#5e8b1e1bb467c937735fecb4cb4b345932151a44"
3519+
integrity sha512-N/LIdTvVc1TpJmMt2jVg0Fr1F7Q1qJPdZSCs19unMskCmVQ/sa0H9L8PWt13vq+gLdLg1+pPsvBLydL1Apahjg==
3520+
dependencies:
3521+
"@formatjs/ecma402-abstract" "2.3.3"
3522+
tslib "2"
3523+
3524+
"@formatjs/[email protected]":
3525+
version "0.6.0"
3526+
resolved "https://registry.yarnpkg.com/@formatjs/intl-localematcher/-/intl-localematcher-0.6.0.tgz#33cf0d33279572c990e02ab75a93122569878082"
3527+
integrity sha512-4rB4g+3hESy1bHSBG3tDFaMY2CH67iT7yne1e+0CLTsGLDcmoEWWpJjjpWVaYgYfYuohIRuo0E+N536gd2ZHZA==
3528+
dependencies:
3529+
tslib "2"
3530+
3531+
"@formatjs/intl-localematcher@^0.5.4":
3532+
version "0.5.10"
3533+
resolved "https://registry.yarnpkg.com/@formatjs/intl-localematcher/-/intl-localematcher-0.5.10.tgz#1e0bd3fc1332c1fe4540cfa28f07e9227b659a58"
3534+
integrity sha512-af3qATX+m4Rnd9+wHcjJ4w2ijq+rAVP3CCinJQvFv1kgSu1W6jypUmvleJxcewdxmutM8dmIRZFxO/IQBZmP2Q==
3535+
dependencies:
3536+
tslib "2"
3537+
34903538
"@hookform/resolvers@^3.8.0":
34913539
version "3.9.0"
34923540
resolved "https://registry.yarnpkg.com/@hookform/resolvers/-/resolvers-3.9.0.tgz#cf540ac21c6c0cd24a40cf53d8e6d64391fb753d"
@@ -7889,6 +7937,11 @@ decimal.js-light@^2.4.1:
78897937
resolved "https://registry.yarnpkg.com/decimal.js-light/-/decimal.js-light-2.5.1.tgz#134fd32508f19e208f4fb2f8dac0d2626a867934"
78907938
integrity sha512-qIMFpTMZmny+MMIitAB6D7iVPEorVw6YQRWkvarTkT4tBeSLLiHzcwj6q0MmYSFCiVpiqPJTJEYIrpcPzVEIvg==
78917939

7940+
decimal.js@10:
7941+
version "10.5.0"
7942+
resolved "https://registry.yarnpkg.com/decimal.js/-/decimal.js-10.5.0.tgz#0f371c7cf6c4898ce0afb09836db73cd82010f22"
7943+
integrity sha512-8vDa8Qxvr/+d94hSh5P3IJwI5t8/c0KsMp+g8bNw9cY2icONa5aPfvKeieW1WlG0WQYwwhJ7mjui2xtiePQSXw==
7944+
78927945
decode-named-character-reference@^1.0.0:
78937946
version "1.0.2"
78947947
resolved "https://registry.yarnpkg.com/decode-named-character-reference/-/decode-named-character-reference-1.0.2.tgz#daabac9690874c394c81e4162a0304b35d824f0e"
@@ -10076,6 +10129,16 @@ internal-slot@^1.0.4, internal-slot@^1.0.5:
1007610129
resolved "https://registry.yarnpkg.com/internmap/-/internmap-2.0.3.tgz#6685f23755e43c524e251d29cbc97248e3061009"
1007710130
integrity sha512-5Hh7Y1wQbvY5ooGgPbDaL5iYLAPzMTUrjMulskHLH6wnv/A+1q5rgEaiuqEjB+oxGXIVZs1FF+R/KPN3ZSQYYg==
1007810131

10132+
intl-messageformat@^10.5.14:
10133+
version "10.7.15"
10134+
resolved "https://registry.yarnpkg.com/intl-messageformat/-/intl-messageformat-10.7.15.tgz#5cdc62139ef39ece1b083db32dae4d1c9fa5b627"
10135+
integrity sha512-LRyExsEsefQSBjU2p47oAheoKz+EOJxSLDdjOaEjdriajfHsMXOmV/EhMvYSg9bAgCUHasuAC+mcUBe/95PfIg==
10136+
dependencies:
10137+
"@formatjs/ecma402-abstract" "2.3.3"
10138+
"@formatjs/fast-memoize" "2.2.6"
10139+
"@formatjs/icu-messageformat-parser" "2.11.1"
10140+
tslib "2"
10141+
1007910142
invariant@^2.2.1, invariant@^2.2.4:
1008010143
version "2.2.4"
1008110144
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
@@ -11631,6 +11694,11 @@ [email protected]:
1163111694
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.3.tgz#58e323a72fedc0d6f9cd4d31fe49f51479590ccd"
1163211695
integrity sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==
1163311696

11697+
negotiator@^1.0.0:
11698+
version "1.0.0"
11699+
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-1.0.0.tgz#b6c91bb47172d69f93cfd7c357bbb529019b5f6a"
11700+
integrity sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==
11701+
1163411702
neo-async@^2.5.0, neo-async@^2.6.2:
1163511703
version "2.6.2"
1163611704
resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f"
@@ -11647,6 +11715,15 @@ next-i18next@^14.0.3:
1164711715
hoist-non-react-statics "^3.3.2"
1164811716
i18next-fs-backend "^2.1.5"
1164911717

11718+
next-intl@^3.26.3:
11719+
version "3.26.3"
11720+
resolved "https://registry.yarnpkg.com/next-intl/-/next-intl-3.26.3.tgz#4991ba09de7d09d8a3e1a75b2cdf28a9648a4b70"
11721+
integrity sha512-6Y97ODrDsEE1J8cXKMHwg1laLdtkN66QMIqG8BzH4zennJRUNTtM8UMtBDyhfmF6uiZ+xsbWLXmHUgmUymUsfQ==
11722+
dependencies:
11723+
"@formatjs/intl-localematcher" "^0.5.4"
11724+
negotiator "^1.0.0"
11725+
use-intl "^3.26.3"
11726+
1165011727
next-mdx-remote@^3.0.8:
1165111728
version "3.0.8"
1165211729
resolved "https://registry.yarnpkg.com/next-mdx-remote/-/next-mdx-remote-3.0.8.tgz#ea2e7f9f3c99a0ce8167976c547e621d5930e1e0"
@@ -14502,6 +14579,11 @@ tsconfig-paths@^4.0.0, tsconfig-paths@^4.1.2, tsconfig-paths@^4.2.0:
1450214579
minimist "^1.2.6"
1450314580
strip-bom "^3.0.0"
1450414581

14582+
tslib@2:
14583+
version "2.8.1"
14584+
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.1.tgz#612efe4ed235d567e8aba5f2a5fab70280ade83f"
14585+
integrity sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==
14586+
1450514587
1450614588
version "2.4.0"
1450714589
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.0.tgz#7cecaa7f073ce680a05847aa77be941098f36dc3"
@@ -14907,6 +14989,14 @@ use-callback-ref@^1.3.0:
1490714989
dependencies:
1490814990
tslib "^2.0.0"
1490914991

14992+
use-intl@^3.26.3:
14993+
version "3.26.3"
14994+
resolved "https://registry.yarnpkg.com/use-intl/-/use-intl-3.26.3.tgz#948c37388c1bfc894504f040930a32791b0158cf"
14995+
integrity sha512-yY0a2YseO17cKwHA9M6fcpiEJ2Uo81DEU0NOUxNTp6lJVNOuI6nULANPVVht6IFdrYFtlsMmMoc97+Eq9/Tnng==
14996+
dependencies:
14997+
"@formatjs/fast-memoize" "^2.2.0"
14998+
intl-messageformat "^10.5.14"
14999+
1491015000
use-isomorphic-layout-effect@^1.1.2:
1491115001
version "1.1.2"
1491215002
resolved "https://registry.yarnpkg.com/use-isomorphic-layout-effect/-/use-isomorphic-layout-effect-1.1.2.tgz#497cefb13d863d687b08477d9e5a164ad8c1a6fb"

0 commit comments

Comments
 (0)