From d768bb163a4854ca618ad99ba5857e13c201a3c4 Mon Sep 17 00:00:00 2001 From: vlalx <143875984+vlalx@users.noreply.github.com> Date: Tue, 3 Jun 2025 21:10:00 +0300 Subject: [PATCH] I18n additionals (#125) * New translation keys * Updates in src/components * Updates in src/providers * remove lable in selector, not needed --------- Co-authored-by: Lokowitz --- messages/de-DE.json | 14 +++++++++++++- messages/en-US.json | 14 +++++++++++++- messages/fr-FR.json | 14 +++++++++++++- messages/it-IT.json | 14 +++++++++++++- messages/pl-PL.json | 14 +++++++++++++- messages/pt-PT.json | 14 +++++++++++++- messages/tr-TR.json | 14 +++++++++++++- src/components/Disable2FaForm.tsx | 14 +++++++------- src/components/LocaleSwitcher.tsx | 31 +++++++++++++++--------------- src/components/LoginForm.tsx | 26 ++++++++++++------------- src/providers/ApiKeyProvider.tsx | 5 ++++- src/providers/OrgProvider.tsx | 7 +++++-- src/providers/OrgUserProvider.tsx | 5 ++++- src/providers/ResourceProvider.tsx | 7 +++++-- src/providers/SiteProvider.tsx | 5 ++++- src/providers/UserProvider.tsx | 5 ++++- 16 files changed, 152 insertions(+), 51 deletions(-) diff --git a/messages/de-DE.json b/messages/de-DE.json index 780377d8..4ae478f1 100644 --- a/messages/de-DE.json +++ b/messages/de-DE.json @@ -1063,5 +1063,17 @@ "inviteErrorInvalidConfirmation": "Ungültige Bestätigung", "passwordRequired": "Passwort ist erforderlich", "allowAll": "Alle erlauben", - "permissionsAllowAll": "Alle Berechtigungen erlauben" + "permissionsAllowAll": "Alle Berechtigungen erlauben", + "githubUsernameRequired": "GitHub-Benutzername ist erforderlich", + "supportKeyRequired": "Unterstützer-Schlüssel ist erforderlich", + "passwordRequirementsChars": "Das Passwort muss mindestens 8 Zeichen lang sein", + "language": "Sprache", + "verificationCodeRequired": "Code ist erforderlich", + "userErrorNoUpdate": "Kein Benutzer zum Aktualisieren", + "siteErrorNoUpdate": "Keine Site zum Aktualisieren", + "resourceErrorNoUpdate": "Keine Ressource zum Aktualisieren", + "authErrorNoUpdate": "Keine Auth-Informationen zum Aktualisieren", + "orgErrorNoUpdate": "Keine Organisation zum Aktualisieren", + "orgErrorNoProvided": "Keine Organisation angegeben", + "apiKeysErrorNoUpdate": "Kein API-Schlüssel zum Aktualisieren" } diff --git a/messages/en-US.json b/messages/en-US.json index d63ef985..6eb8d8af 100644 --- a/messages/en-US.json +++ b/messages/en-US.json @@ -1063,5 +1063,17 @@ "inviteErrorInvalidConfirmation": "Invalid confirmation", "passwordRequired": "Password is required", "allowAll": "Allow All", - "permissionsAllowAll": "Allow All Permissions" + "permissionsAllowAll": "Allow All Permissions", + "githubUsernameRequired": "GitHub username is required", + "supportKeyRequired": "Supporter key is required", + "passwordRequirementsChars": "Password must be at least 8 characters", + "language": "Language", + "verificationCodeRequired": "Code is required", + "userErrorNoUpdate": "No user to update", + "siteErrorNoUpdate": "No site to update", + "resourceErrorNoUpdate": "No resource to update", + "authErrorNoUpdate": "No auth info to update", + "orgErrorNoUpdate": "No org to update", + "orgErrorNoProvided": "No org provided", + "apiKeysErrorNoUpdate": "No API key to update" } diff --git a/messages/fr-FR.json b/messages/fr-FR.json index 14935896..fb59e65a 100644 --- a/messages/fr-FR.json +++ b/messages/fr-FR.json @@ -1063,5 +1063,17 @@ "inviteErrorInvalidConfirmation": "Confirmation invalide", "passwordRequired": "Le mot de passe est requis", "allowAll": "Tout autoriser", - "permissionsAllowAll": "Autoriser toutes les autorisations" + "permissionsAllowAll": "Autoriser toutes les autorisations", + "githubUsernameRequired": "Le nom d'utilisateur GitHub est requis", + "supportKeyRequired": "La clé de supporter est requise", + "passwordRequirementsChars": "Le mot de passe doit comporter au moins 8 caractères", + "language": "Langue", + "verificationCodeRequired": "Le code est requis", + "userErrorNoUpdate": "Pas d'utilisateur à mettre à jour", + "siteErrorNoUpdate": "Pas de site à mettre à jour", + "resourceErrorNoUpdate": "Pas de ressource à mettre à jour", + "authErrorNoUpdate": "Pas d'informations d'authentification à mettre à jour", + "orgErrorNoUpdate": "Pas d'organisation à mettre à jour", + "orgErrorNoProvided": "Aucune organisation fournie", + "apiKeysErrorNoUpdate": "Pas de clé API à mettre à jour" } diff --git a/messages/it-IT.json b/messages/it-IT.json index 3ca4f87c..3e49a833 100644 --- a/messages/it-IT.json +++ b/messages/it-IT.json @@ -1063,5 +1063,17 @@ "inviteErrorInvalidConfirmation": "Conferma non valida", "passwordRequired": "La password è obbligatoria", "allowAll": "Consenti Tutto", - "permissionsAllowAll": "Consenti Tutti I Permessi" + "permissionsAllowAll": "Consenti Tutti I Permessi", + "githubUsernameRequired": "È richiesto l'username GitHub", + "supportKeyRequired": "È richiesta la chiave di supporto", + "passwordRequirementsChars": "La password deve essere di almeno 8 caratteri", + "language": "Lingua", + "verificationCodeRequired": "È richiesto un codice", + "userErrorNoUpdate": "Nessun utente da aggiornare", + "siteErrorNoUpdate": "Nessun sito da aggiornare", + "resourceErrorNoUpdate": "Nessuna risorsa da aggiornare", + "authErrorNoUpdate": "Nessuna informazione di autenticazione da aggiornare", + "orgErrorNoUpdate": "Nessuna organizzazione da aggiornare", + "orgErrorNoProvided": "Nessuna organizzazione fornita", + "apiKeysErrorNoUpdate": "Nessuna chiave API da aggiornare" } diff --git a/messages/pl-PL.json b/messages/pl-PL.json index fbdd3c1d..299e5502 100644 --- a/messages/pl-PL.json +++ b/messages/pl-PL.json @@ -1063,5 +1063,17 @@ "inviteErrorInvalidConfirmation": "Nieprawidłowe potwierdzenie", "passwordRequired": "Hasło jest wymagane", "allowAll": "Zezwól wszystkim", - "permissionsAllowAll": "Zezwól na wszystkie uprawnienia" + "permissionsAllowAll": "Zezwól na wszystkie uprawnienia", + "githubUsernameRequired": "Nazwa użytkownika GitHub jest wymagana", + "supportKeyRequired": "Klucz wspierający jest wymagany", + "passwordRequirementsChars": "Hasło musi mieć co najmniej 8 znaków", + "language": "Język", + "verificationCodeRequired": "Kod jest wymagany", + "userErrorNoUpdate": "Brak użytkownika do aktualizacji", + "siteErrorNoUpdate": "Brak witryny do aktualizacji", + "resourceErrorNoUpdate": "Brak zasobu do aktualizacji", + "authErrorNoUpdate": "Brak danych uwierzytelniania do aktualizacji", + "orgErrorNoUpdate": "Brak organizacji do aktualizacji", + "orgErrorNoProvided": "Nie podano organizacji", + "apiKeysErrorNoUpdate": "Brak klucza API do aktualizacji" } diff --git a/messages/pt-PT.json b/messages/pt-PT.json index 2bd0a29e..986d889c 100644 --- a/messages/pt-PT.json +++ b/messages/pt-PT.json @@ -1063,5 +1063,17 @@ "inviteErrorInvalidConfirmation": "Confirmação inválida", "passwordRequired": "A senha é obrigatória", "allowAll": "Permitir todos", - "permissionsAllowAll": "Permitir Todas as Permissões" + "permissionsAllowAll": "Permitir Todas as Permissões", + "githubUsernameRequired": "O nome de utilizador GitHub é obrigatório", + "supportKeyRequired": "A chave de apoiante é obrigatória", + "passwordRequirementsChars": "A palavra-passe deve ter pelo menos 8 caracteres", + "language": "Idioma", + "verificationCodeRequired": "O código é obrigatório", + "userErrorNoUpdate": "Não existe utilizador para atualizar", + "siteErrorNoUpdate": "Não existe site para atualizar", + "resourceErrorNoUpdate": "Não existe recurso para atualizar", + "authErrorNoUpdate": "Não existem informações de autenticação para atualizar", + "orgErrorNoUpdate": "Não existe organização para atualizar", + "orgErrorNoProvided": "Nenhuma organização fornecida", + "apiKeysErrorNoUpdate": "Não existe chave API para atualizar" } diff --git a/messages/tr-TR.json b/messages/tr-TR.json index 574737bb..5e1b88db 100644 --- a/messages/tr-TR.json +++ b/messages/tr-TR.json @@ -1063,5 +1063,17 @@ "inviteErrorInvalidConfirmation": "Invalid confirmation", "passwordRequired": "Password is required", "allowAll": "Allow All", - "permissionsAllowAll": "Allow All Permissions" + "permissionsAllowAll": "Allow All Permissions", + "githubUsernameRequired": "GitHub username is required", + "supportKeyRequired": "Supporter key is required", + "passwordRequirementsChars": "Password must be at least 8 characters", + "language": "Language", + "verificationCodeRequired": "Code is required", + "userErrorNoUpdate": "No user to update", + "siteErrorNoUpdate": "No site to update", + "resourceErrorNoUpdate": "No resource to update", + "authErrorNoUpdate": "No auth info to update", + "orgErrorNoUpdate": "No org to update", + "orgErrorNoProvided": "No org provided", + "apiKeysErrorNoUpdate": "No API key to update" } diff --git a/src/components/Disable2FaForm.tsx b/src/components/Disable2FaForm.tsx index c9c1d228..06f57d4f 100644 --- a/src/components/Disable2FaForm.tsx +++ b/src/components/Disable2FaForm.tsx @@ -34,11 +34,6 @@ import { useUserContext } from "@app/hooks/useUserContext"; import { CheckCircle2 } from "lucide-react"; import { useTranslations } from "next-intl"; -const disableSchema = z.object({ - password: z.string().min(1, { message: "Password is required" }), - code: z.string().min(1, { message: "Code is required" }) -}); - type Disable2FaProps = { open: boolean; setOpen: (val: boolean) => void; @@ -53,6 +48,13 @@ export default function Disable2FaForm({ open, setOpen }: Disable2FaProps) { const api = createApiClient(useEnvContext()); + const t = useTranslations(); + + const disableSchema = z.object({ + password: z.string().min(1, { message: t('passwordRequired') }), + code: z.string().min(1, { message: t('verificationCodeRequired') }) + }); + const disableForm = useForm>({ resolver: zodResolver(disableSchema), defaultValues: { @@ -61,8 +63,6 @@ export default function Disable2FaForm({ open, setOpen }: Disable2FaProps) { } }); - const t = useTranslations(); - const request2fa = async (values: z.infer) => { setLoading(true); diff --git a/src/components/LocaleSwitcher.tsx b/src/components/LocaleSwitcher.tsx index 962b39bb..651a70e6 100644 --- a/src/components/LocaleSwitcher.tsx +++ b/src/components/LocaleSwitcher.tsx @@ -1,4 +1,4 @@ -import { useLocale } from 'next-intl'; +import { useLocale } from "next-intl"; import LocaleSwitcherSelect from './LocaleSwitcherSelect'; export default function LocaleSwitcher() { @@ -9,35 +9,34 @@ export default function LocaleSwitcher() { defaultValue={locale} items={[ { - value: 'en-US', - label: 'Englisch' + value: 'en-US', + label: 'English' }, { - value: 'fr-FR', - label: 'French' + value: 'fr-FR', + label: "Français" }, { - value: 'de-DE', - label: 'German' + value: 'de-DE', + label: 'Deutsch' }, { - value: 'it-IT', - label: 'Italian' + value: 'it-IT', + label: 'Italiano' }, { - value: 'pl-PL', - label: 'Polish' + value: 'pl-PL', + label: 'Polski' }, { - value: 'pt-PT', - label: 'Portuguese' + value: 'pt-PT', + label: 'Português' }, { - value: 'tr-TR', - label: 'Turkish' + value: 'tr-TR', + label: 'Türkçe' } ]} - label='Language' /> ); } diff --git a/src/components/LoginForm.tsx b/src/components/LoginForm.tsx index d0eee1b7..14189c37 100644 --- a/src/components/LoginForm.tsx +++ b/src/components/LoginForm.tsx @@ -53,17 +53,6 @@ type LoginFormProps = { idps?: LoginFormIDP[]; }; -const formSchema = z.object({ - email: z.string().email({ message: "Invalid email address" }), - password: z - .string() - .min(8, { message: "Password must be at least 8 characters" }) -}); - -const mfaSchema = z.object({ - code: z.string().length(6, { message: "Invalid code" }) -}); - export default function LoginForm({ redirect, onLogin, idps }: LoginFormProps) { const router = useRouter(); @@ -77,6 +66,19 @@ export default function LoginForm({ redirect, onLogin, idps }: LoginFormProps) { const [mfaRequested, setMfaRequested] = useState(false); + const t = useTranslations(); + + const formSchema = z.object({ + email: z.string().email({ message: t('emailInvalid') }), + password: z + .string() + .min(8, { message: t('passwordRequirementsChars') }) + }); + + const mfaSchema = z.object({ + code: z.string().length(6, { message: t('pincodeInvalid') }) + }); + const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { @@ -92,8 +94,6 @@ export default function LoginForm({ redirect, onLogin, idps }: LoginFormProps) { } }); - const t = useTranslations(); - async function onSubmit(values: any) { const { email, password } = form.getValues(); const { code } = mfaForm.getValues(); diff --git a/src/providers/ApiKeyProvider.tsx b/src/providers/ApiKeyProvider.tsx index 43a2a9b6..80563ac0 100644 --- a/src/providers/ApiKeyProvider.tsx +++ b/src/providers/ApiKeyProvider.tsx @@ -3,6 +3,7 @@ import ApiKeyContext from "@app/contexts/apiKeyContext"; import { GetApiKeyResponse } from "@server/routers/apiKeys"; import { useState } from "react"; +import { useTranslations } from "next-intl"; interface ApiKeyProviderProps { children: React.ReactNode; @@ -12,9 +13,11 @@ interface ApiKeyProviderProps { export function ApiKeyProvider({ children, apiKey: ak }: ApiKeyProviderProps) { const [apiKey, setApiKey] = useState(ak); + const t = useTranslations(); + const updateApiKey = (updatedApiKey: Partial) => { if (!apiKey) { - throw new Error("No API key to update"); + throw new Error(t('apiKeysErrorNoUpdate')); } setApiKey((prev) => { if (!prev) { diff --git a/src/providers/OrgProvider.tsx b/src/providers/OrgProvider.tsx index 73531931..0eff0183 100644 --- a/src/providers/OrgProvider.tsx +++ b/src/providers/OrgProvider.tsx @@ -3,6 +3,7 @@ import OrgContext from "@app/contexts/orgContext"; import { GetOrgResponse } from "@server/routers/org"; import { useState } from "react"; +import { useTranslations } from "next-intl"; interface OrgProviderProps { children: React.ReactNode; @@ -12,13 +13,15 @@ interface OrgProviderProps { export function OrgProvider({ children, org: serverOrg }: OrgProviderProps) { const [org, setOrg] = useState(serverOrg); + const t = useTranslations(); + if (!org) { - throw new Error("No org provided"); + throw new Error(t('orgErrorNoProvided')); } const updateOrg = (updatedOrg: Partial) => { if (!org) { - throw new Error("No org to update"); + throw new Error(t('orgErrorNoUpdate')); } setOrg((prev) => { diff --git a/src/providers/OrgUserProvider.tsx b/src/providers/OrgUserProvider.tsx index 9234f9ba..7606cab1 100644 --- a/src/providers/OrgUserProvider.tsx +++ b/src/providers/OrgUserProvider.tsx @@ -3,6 +3,7 @@ import OrgUserContext from "@app/contexts/orgUserContext"; import { GetOrgUserResponse } from "@server/routers/user"; import { useState } from "react"; +import { useTranslations } from "next-intl"; interface OrgUserProviderProps { children: React.ReactNode; @@ -15,9 +16,11 @@ export function OrgUserProvider({ }: OrgUserProviderProps) { const [orgUser, setOrgUser] = useState(serverOrgUser); + const t = useTranslations(); + const updateOrgUser = (updateOrgUser: Partial) => { if (!orgUser) { - throw new Error("No org to update"); + throw new Error(t('orgErrorNoUpdate')); } setOrgUser((prev) => { diff --git a/src/providers/ResourceProvider.tsx b/src/providers/ResourceProvider.tsx index cd6229a4..5e4ce6ea 100644 --- a/src/providers/ResourceProvider.tsx +++ b/src/providers/ResourceProvider.tsx @@ -4,6 +4,7 @@ import ResourceContext from "@app/contexts/resourceContext"; import { GetResourceAuthInfoResponse } from "@server/routers/resource"; import { GetResourceResponse } from "@server/routers/resource/getResource"; import { useState } from "react"; +import { useTranslations } from "next-intl"; interface ResourceProviderProps { children: React.ReactNode; @@ -22,9 +23,11 @@ export function ResourceProvider({ const [authInfo, setAuthInfo] = useState(serverAuthInfo); + const t = useTranslations(); + const updateResource = (updatedResource: Partial) => { if (!resource) { - throw new Error("No resource to update"); + throw new Error(t('resourceErrorNoUpdate')); } setResource((prev) => { @@ -43,7 +46,7 @@ export function ResourceProvider({ updatedAuthInfo: Partial ) => { if (!authInfo) { - throw new Error("No auth info to update"); + throw new Error(t('authErrorNoUpdate')); } setAuthInfo((prev) => { diff --git a/src/providers/SiteProvider.tsx b/src/providers/SiteProvider.tsx index 73b70053..0bb35a50 100644 --- a/src/providers/SiteProvider.tsx +++ b/src/providers/SiteProvider.tsx @@ -3,6 +3,7 @@ import SiteContext from "@app/contexts/siteContext"; import { GetSiteResponse } from "@server/routers/site/getSite"; import { useState } from "react"; +import { useTranslations } from "next-intl"; interface SiteProviderProps { children: React.ReactNode; @@ -15,9 +16,11 @@ export function SiteProvider({ }: SiteProviderProps) { const [site, setSite] = useState(serverSite); + const t = useTranslations(); + const updateSite = (updatedSite: Partial) => { if (!site) { - throw new Error("No site to update"); + throw new Error(t('siteErrorNoUpdate')); } setSite((prev) => { if (!prev) { diff --git a/src/providers/UserProvider.tsx b/src/providers/UserProvider.tsx index faa37fa7..59bff234 100644 --- a/src/providers/UserProvider.tsx +++ b/src/providers/UserProvider.tsx @@ -3,6 +3,7 @@ import UserContext from "@app/contexts/userContext"; import { GetUserResponse } from "@server/routers/user"; import { useState } from "react"; +import { useTranslations } from "next-intl"; interface UserProviderProps { children: React.ReactNode; @@ -12,9 +13,11 @@ interface UserProviderProps { export function UserProvider({ children, user: u }: UserProviderProps) { const [user, setUser] = useState(u); + const t = useTranslations(); + const updateUser = (updatedUser: Partial) => { if (!user) { - throw new Error("No user to update"); + throw new Error(t('userErrorNoUpdate')); } setUser((prev) => { if (!prev) {