mirror of
https://github.com/Lapikud/tipilan.git
synced 2026-03-23 21:34:21 +00:00
Add English translation to page with next-intl
This commit is contained in:
17
src/i18n/request.ts
Normal file
17
src/i18n/request.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { getRequestConfig } from "next-intl/server";
|
||||
import { routing } from "./routing";
|
||||
|
||||
export default getRequestConfig(async ({ requestLocale }) => {
|
||||
// This typically corresponds to the `[locale]` segment
|
||||
let locale = await requestLocale;
|
||||
|
||||
// Ensure that a valid locale is used
|
||||
if (!locale || !routing.locales.includes(locale as "et" | "en")) {
|
||||
locale = routing.defaultLocale;
|
||||
}
|
||||
|
||||
return {
|
||||
locale: locale!,
|
||||
messages: (await import(`../../translations/${locale}.json`)).default,
|
||||
};
|
||||
});
|
||||
55
src/i18n/routing.ts
Normal file
55
src/i18n/routing.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { defineRouting } from "next-intl/routing";
|
||||
import { createNavigation } from "next-intl/navigation";
|
||||
|
||||
export const routing = defineRouting({
|
||||
// A list of all locales that are supported
|
||||
locales: ["et", "en"],
|
||||
|
||||
// Used when no locale matches
|
||||
defaultLocale: "et",
|
||||
|
||||
// The `pathnames` object holds pairs of internal and
|
||||
// external paths. The external paths are shown in the URL.
|
||||
pathnames: {
|
||||
// If all locales use the same pathname, a single
|
||||
// external path can be used for all locales
|
||||
"/": "/",
|
||||
"/ajakava": {
|
||||
et: "/ajakava",
|
||||
en: "/schedule",
|
||||
},
|
||||
"/haldus": {
|
||||
et: "/haldus",
|
||||
en: "/admin",
|
||||
},
|
||||
"/kodukord": {
|
||||
et: "/kodukord",
|
||||
en: "/rules",
|
||||
},
|
||||
"/messiala": {
|
||||
et: "/messiala",
|
||||
en: "/expo",
|
||||
},
|
||||
"/piletid": {
|
||||
et: "/piletid",
|
||||
en: "/tickets",
|
||||
},
|
||||
"/reeglid": {
|
||||
et: "/reeglid",
|
||||
en: "/regulations",
|
||||
},
|
||||
"/striim": {
|
||||
et: "/striim",
|
||||
en: "/stream",
|
||||
},
|
||||
"/turniirid": {
|
||||
et: "/turniirid",
|
||||
en: "/tournaments",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Lightweight wrappers around Next.js' navigation APIs
|
||||
// that will consider the routing configuration
|
||||
export const { Link, redirect, usePathname, useRouter } =
|
||||
createNavigation(routing);
|
||||
Reference in New Issue
Block a user