feat: add next-international translations (#2)
* feat: add next-international translations * chore: fix formatting * chore: address pull request feedback
This commit is contained in:
1
packages/translation/index.ts
Normal file
1
packages/translation/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./src";
|
||||
41
packages/translation/package.json
Normal file
41
packages/translation/package.json
Normal 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"
|
||||
}
|
||||
}
|
||||
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());
|
||||
8
packages/translation/tsconfig.json
Normal file
8
packages/translation/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "@alparr/tsconfig/base.json",
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
|
||||
},
|
||||
"include": ["*.ts", "src"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
@@ -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",
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user