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 @@
export * from "./src";

View File

@@ -0,0 +1,41 @@
{
"name": "@alparr/translation",
"private": true,
"version": "0.1.0",
"exports": {
".": "./index.ts",
"./client": "./src/client.ts",
"./server": "./src/server.ts",
"./middleware": "./src/middleware.ts"
},
"typesVersions": {
"*": {
"*": [
"src/*"
]
}
},
"license": "MIT",
"scripts": {
"clean": "rm -rf .turbo node_modules",
"lint": "eslint .",
"format": "prettier --check . --ignore-path ../../.gitignore",
"typecheck": "tsc --noEmit"
},
"devDependencies": {
"@alparr/eslint-config": "workspace:^0.2.0",
"@alparr/prettier-config": "workspace:^0.1.0",
"@alparr/tsconfig": "workspace:^0.1.0",
"eslint": "^8.53.0",
"typescript": "^5.3.3"
},
"eslintConfig": {
"extends": [
"@alparr/eslint-config/base"
]
},
"prettier": "@alparr/prettier-config",
"dependencies": {
"next-international": "^1.1.4"
}
}

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());

View File

@@ -0,0 +1,8 @@
{
"extends": "@alparr/tsconfig/base.json",
"compilerOptions": {
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
},
"include": ["*.ts", "src"],
"exclude": ["node_modules"]
}

View File

@@ -7,10 +7,10 @@ export const initUserSchema = z
.object({
username: usernameSchema,
password: passwordSchema,
repeatPassword: z.string(),
confirmPassword: z.string(),
})
.refine((data) => data.password === data.repeatPassword, {
path: ["repeatPassword"],
.refine((data) => data.password === data.confirmPassword, {
path: ["confirmPassword"],
message: "Passwords do not match",
});