feat: add next-international translations (#2)
* feat: add next-international translations * chore: fix formatting * chore: address pull request feedback
This commit is contained in:
8
packages/translation/src/client.ts
Normal file
8
packages/translation/src/client.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
"use client";
|
||||
|
||||
import { createI18nClient } from "next-international/client";
|
||||
|
||||
import { languageMapping } from "./lang";
|
||||
|
||||
export const { useI18n, useScopedI18n, I18nProviderClient } =
|
||||
createI18nClient(languageMapping());
|
||||
4
packages/translation/src/index.ts
Normal file
4
packages/translation/src/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export const supportedLanguages = ["en", "de"] as const;
|
||||
export type SupportedLanguage = (typeof supportedLanguages)[number];
|
||||
|
||||
export const defaultLocale = "en";
|
||||
17
packages/translation/src/lang.ts
Normal file
17
packages/translation/src/lang.ts
Normal 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>
|
||||
>;
|
||||
};
|
||||
29
packages/translation/src/lang/de.ts
Normal file
29
packages/translation/src/lang/de.ts
Normal 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;
|
||||
29
packages/translation/src/lang/en.ts
Normal file
29
packages/translation/src/lang/en.ts
Normal 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;
|
||||
9
packages/translation/src/middleware.ts
Normal file
9
packages/translation/src/middleware.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { createI18nMiddleware } from "next-international/middleware";
|
||||
|
||||
import { defaultLocale, supportedLanguages } from ".";
|
||||
|
||||
export const I18nMiddleware = createI18nMiddleware({
|
||||
locales: supportedLanguages,
|
||||
defaultLocale,
|
||||
urlMappingStrategy: "rewrite",
|
||||
});
|
||||
6
packages/translation/src/server.ts
Normal file
6
packages/translation/src/server.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { createI18nServer } from "next-international/server";
|
||||
|
||||
import { languageMapping } from "./lang";
|
||||
|
||||
export const { getI18n, getScopedI18n, getStaticParams } =
|
||||
createI18nServer(languageMapping());
|
||||
Reference in New Issue
Block a user