Skip to content

Commit 33f2db0

Browse files
feat: upgrade to new i18n conventions (#337)
1 parent d01a8f9 commit 33f2db0

File tree

19 files changed

+68
-110
lines changed

19 files changed

+68
-110
lines changed

package-lock.json

Lines changed: 23 additions & 74 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"lightweight-charts": "^4.1.4",
3232
"luxon": "^3.4.4",
3333
"next": "^14.2.3",
34-
"next-intl": "^3.14.1",
34+
"next-intl": "^3.19.1",
3535
"papaparse": "^5.4.1",
3636
"postcss": "8.4.31",
3737
"pretty-ms": "^8.0.0",

src/app/[locale]/not-found.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Link } from "@/navigation";
1+
import { Link } from "@/i18n/routing";
22

33
export default function NotFound() {
44
return (

src/app/sitemap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defaultLocale, locales } from "@/navigation";
1+
import { defaultLocale, locales } from "@/i18n/locales";
22
import { MetadataRoute } from "next";
33

44
const pathnames = ["/", "/cubes", "/solves", "/stats"];

src/components/Select.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { useRef, useState } from "react";
22
import Image from "next/image";
3-
import { Link } from "@/navigation";
43
import { Categories } from "@/interfaces/Categories";
54
import { cubeCollection } from "@/lib/const/cubeCollection";
65
import genId from "@/lib/genId";
@@ -12,6 +11,7 @@ import { useBackgroundImageStore } from "@/store/BackgroundThemeStore";
1211
import { Cube } from "@/interfaces/Cube";
1312
import { useTranslations } from "next-intl";
1413
import { ChevronUpDownIcon, PlusIcon } from "@heroicons/react/24/solid";
14+
import { Link } from "@/i18n/routing";
1515

1616
export default function Select() {
1717
const [open, setOpen] = useState<boolean>(false);

src/components/cubes/TableRow.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Cube } from "@/interfaces/Cube";
22
import BookmarkFav from "@/components/cubes/BookmarkFav";
33
import { useTimerStore } from "@/store/timerStore";
44
import { useCubesModalStore } from "@/store/CubesModalStore";
5-
import { useRouter } from "@/navigation";
5+
import { useRouter } from "@/i18n/routing";
66
import { getAllCubes, saveCube } from "@/db/dbOperations";
77
import { useTranslations, useLocale } from "next-intl";
88
import { DateTime } from "luxon";
@@ -72,8 +72,8 @@ export default function TableRow({ cube }: { cube: Cube }) {
7272
</div>
7373
<div className="hidden text-center align-middle cursor-pointer md:table-cell">
7474
{DateTime.fromMillis(cube?.createdAt)
75-
.setLocale(locale)
76-
.toLocaleString()}
75+
.setLocale(locale)
76+
.toLocaleString()}
7777
</div>
7878
<div className="hidden text-center align-middle md:table-cell">
7979
{cube?.solves?.session.length > 0 ? (

src/components/menu-settings/ImportModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { useSettingsModalStore } from "@/store/SettingsModalStore";
44
import { useTimerStore } from "@/store/timerStore";
55
import { AnimatePresence, motion } from "framer-motion";
66
import Image from "next/image";
7-
import { useRouter } from "@/navigation";
87
import { useRef, useState } from "react";
98
import Loading from "../Loading";
109
import { getAllCubes } from "@/db/dbOperations";
1110
import { useTranslations } from "next-intl";
11+
import { useRouter } from "@/i18n/routing";
1212

1313
export default function ImportModal() {
1414
const { setImportModalOpen, importModalOpen } = useSettingsModalStore();

src/components/menu-settings/Menu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { MenuSection } from "@/components/menu-settings/MenuSection";
44
import { MenuOption } from "@/components/menu-settings/MenuOption";
55
import { DataImportExport } from "@/components/menu-settings/DataImportExport";
66
import { useTimerStore } from "@/store/timerStore";
7-
import { Link } from "@/navigation";
7+
import { Link } from "@/i18n/routing";
88
import useEscape from "@/hooks/useEscape";
99
import Image from "next/image";
1010
import { AnimatePresence, motion } from "framer-motion";

src/components/menu-settings/MenuSelectLanguage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { MenuSection } from "./MenuSection";
44
import { useLocale, useTranslations } from "next-intl";
55
import { languages } from "@/lib/const/languages";
66
import { useRef } from "react";
7-
import { useRouter } from "@/navigation";
7+
import { useRouter } from "@/i18n/routing";
88
import { useSettingsModalStore } from "@/store/SettingsModalStore";
99
import { GlobeAltIcon } from "@heroicons/react/24/solid";
1010
import { Button } from "../button";

src/components/navbar/NavItem.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { usePathname } from "@/navigation";
2-
import { Link } from "@/navigation";
1+
import { Link, usePathname } from "@/i18n/routing";
32

43
interface NavItem {
54
path: string;

src/components/solves/EmptySolves.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CubeIcon, CursorArrowRaysIcon } from "@heroicons/react/24/solid";
2-
import { Link } from "@/navigation";
2+
import { Link } from "@/i18n/routing";
33

44
type Icon = "no-cube-selected" | "no-solves";
55

src/components/timer/HeaderTimer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useSettingsModalStore } from "@/store/SettingsModalStore";
33
import { useTimerStore } from "@/store/timerStore";
44
import { InteractiveIcon } from "./InteractiveIcon";
55
import { ScrambleZone } from "./ScrambleZone";
6-
import { Link } from "@/navigation";
6+
import { Link } from "@/i18n/routing";
77
import { useTranslations } from "next-intl";
88
import { ArrowPathIcon, Cog6ToothIcon } from "@heroicons/react/24/solid";
99

src/hooks/useForceHashSettings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { useRouter } from "@/navigation";
3+
import { useRouter } from "@/i18n/routing";
44
import { useEffect } from "react";
55

66
// Resets all hashes on first load

src/navigation.ts renamed to src/i18n/locales.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import { createSharedPathnamesNavigation } from "next-intl/navigation";
2-
3-
export const defaultLocale = "en";
4-
export const localePrefix = "always";
51
export const locales = [
62
"en",
73
"de",
@@ -30,6 +26,6 @@ export const locales = [
3026
"uk",
3127
"vi",
3228
"zh",
33-
] as const;
34-
export const { Link, redirect, usePathname, useRouter } =
35-
createSharedPathnamesNavigation({ locales, localePrefix });
29+
];
30+
31+
export const defaultLocale = "en";

src/i18n.ts renamed to src/i18n/request.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { notFound } from "next/navigation";
22
import { getRequestConfig } from "next-intl/server";
3-
import { locales } from "./navigation";
3+
import { routing } from "./routing";
44
import { merge } from "ts-deepmerge";
55

66
export default getRequestConfig(async ({ locale }) => {
77
// Validate that the incoming `locale` parameter is valid
8-
if (!locales.includes(locale as any)) notFound();
8+
if (!routing.locales.includes(locale as any)) notFound();
99

10-
const userMessages = (await import(`../messages/${locale}.json`)).default;
11-
const defaultMessages = (await import(`../messages/en.json`)).default;
10+
const userMessages = (await import(`../../messages/${locale}.json`)).default;
11+
const defaultMessages = (await import(`../../messages/en.json`)).default;
1212
const messages = merge(defaultMessages, userMessages);
1313

1414
return {

src/i18n/routing.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { defineRouting } from "next-intl/routing";
2+
import { createSharedPathnamesNavigation } from "next-intl/navigation";
3+
import { locales } from "./locales";
4+
5+
export const routing = defineRouting({
6+
// A list of all locales that are supported
7+
locales: [...locales],
8+
9+
localePrefix: "always",
10+
11+
// Used when no locale matches
12+
defaultLocale: "en",
13+
});
14+
15+
// Lightweight wrappers around Next.js' navigation APIs
16+
// that will consider the routing configuration
17+
export const { Link, redirect, usePathname, useRouter } =
18+
createSharedPathnamesNavigation(routing);

src/lib/const/languages.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { locales } from "@/navigation";
21
import {
32
US,
43
ES,
@@ -28,6 +27,7 @@ import {
2827
SK,
2928
EE,
3029
} from "country-flag-icons/react/3x2";
30+
import { locales } from "@/i18n/locales";
3131

3232
interface LanguageProp {
3333
code: (typeof locales)[number];

src/middleware.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import createMiddleware from "next-intl/middleware";
2-
import { locales, localePrefix } from "@/navigation";
3-
export default createMiddleware({
4-
// A list of all locales that are supported
5-
locales,
6-
localePrefix,
7-
localeDetection: true,
8-
defaultLocale: "en",
9-
});
2+
import { routing } from "./i18n/routing";
3+
4+
export default createMiddleware(routing);
105

116
export const config = {
127
matcher: [

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"**/*.ts",
2828
"**/*.tsx",
2929
".next/types/**/*.ts",
30-
"src/components/timer/TimerWidgets.tsx"
30+
"src/components/timer/TimerWidgets.tsx",
31+
"src/i18n/routing.js"
3132
],
3233
"exclude": ["node_modules"]
3334
}

0 commit comments

Comments
 (0)