feat: add next-international translations (#2)

* feat: add next-international translations
* chore: fix formatting
* chore: address pull request feedback
This commit is contained in:
Meier Lukas
2023-12-19 23:09:41 +01:00
committed by GitHub
parent 3cedb7fba5
commit a082f70470
24 changed files with 290 additions and 27 deletions

View File

@@ -0,0 +1,8 @@
"use client";
import { createI18nClient } from "next-international/client";
import { languageMapping } from "./lang";
export const { useI18n, useScopedI18n, I18nProviderClient } =
createI18nClient(languageMapping());

View File

@@ -0,0 +1,4 @@
export const supportedLanguages = ["en", "de"] as const;
export type SupportedLanguage = (typeof supportedLanguages)[number];
export const defaultLocale = "en";

View File

@@ -0,0 +1,17 @@
import { supportedLanguages } from ".";
const enTranslations = () => import("./lang/en");
export const languageMapping = () => {
const mapping: Record<string, unknown> = {};
for (const language of supportedLanguages) {
mapping[language] = () =>
import(`./lang/${language}`) as ReturnType<typeof enTranslations>;
}
return mapping as Record<
(typeof supportedLanguages)[number],
() => ReturnType<typeof enTranslations>
>;
};

View File

@@ -0,0 +1,29 @@
export default {
user: {
page: {
login: {
title: "Melde dich bei deinem Konto an",
subtitle: "Willkommen zurück! Bitte gib deine Zugangsdaten ein",
},
init: {
title: "Neue Alparr Installation",
subtitle: "Bitte erstelle den initialen Administrator Benutzer",
},
},
field: {
username: {
label: "Benutzername",
},
password: {
label: "Passwort",
},
passwordConfirm: {
label: "Passwort bestätigen",
},
},
action: {
login: "Anmelden",
create: "Benutzer erstellen",
},
},
} as const;

View File

@@ -0,0 +1,29 @@
export default {
user: {
page: {
login: {
title: "Log in to your account",
subtitle: "Welcome back! Please enter your credentials",
},
init: {
title: "New Alparr installation",
subtitle: "Please create the initial administator user",
},
},
field: {
username: {
label: "Username",
},
password: {
label: "Password",
},
passwordConfirm: {
label: "Confirm password",
},
},
action: {
login: "Login",
create: "Create user",
},
},
} as const;

View File

@@ -0,0 +1,9 @@
import { createI18nMiddleware } from "next-international/middleware";
import { defaultLocale, supportedLanguages } from ".";
export const I18nMiddleware = createI18nMiddleware({
locales: supportedLanguages,
defaultLocale,
urlMappingStrategy: "rewrite",
});

View File

@@ -0,0 +1,6 @@
import { createI18nServer } from "next-international/server";
import { languageMapping } from "./lang";
export const { getI18n, getScopedI18n, getStaticParams } =
createI18nServer(languageMapping());