I18n additionals (#125)

* New translation keys

* Updates in src/components

* Updates in src/providers

* remove lable in selector, not needed

---------

Co-authored-by: Lokowitz <marvinlokowitz@gmail.com>
This commit is contained in:
vlalx
2025-06-03 21:10:00 +03:00
committed by GitHub
parent dc6fafba41
commit d768bb163a
16 changed files with 152 additions and 51 deletions

View File

@@ -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<z.infer<typeof disableSchema>>({
resolver: zodResolver(disableSchema),
defaultValues: {
@@ -61,8 +63,6 @@ export default function Disable2FaForm({ open, setOpen }: Disable2FaProps) {
}
});
const t = useTranslations();
const request2fa = async (values: z.infer<typeof disableSchema>) => {
setLoading(true);

View File

@@ -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'
/>
);
}

View File

@@ -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<z.infer<typeof formSchema>>({
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();

View File

@@ -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<GetApiKeyResponse>(ak);
const t = useTranslations();
const updateApiKey = (updatedApiKey: Partial<GetApiKeyResponse>) => {
if (!apiKey) {
throw new Error("No API key to update");
throw new Error(t('apiKeysErrorNoUpdate'));
}
setApiKey((prev) => {
if (!prev) {

View File

@@ -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<GetOrgResponse | null>(serverOrg);
const t = useTranslations();
if (!org) {
throw new Error("No org provided");
throw new Error(t('orgErrorNoProvided'));
}
const updateOrg = (updatedOrg: Partial<GetOrgResponse>) => {
if (!org) {
throw new Error("No org to update");
throw new Error(t('orgErrorNoUpdate'));
}
setOrg((prev) => {

View File

@@ -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<GetOrgUserResponse>(serverOrgUser);
const t = useTranslations();
const updateOrgUser = (updateOrgUser: Partial<GetOrgUserResponse>) => {
if (!orgUser) {
throw new Error("No org to update");
throw new Error(t('orgErrorNoUpdate'));
}
setOrgUser((prev) => {

View File

@@ -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<GetResourceAuthInfoResponse>(serverAuthInfo);
const t = useTranslations();
const updateResource = (updatedResource: Partial<GetResourceResponse>) => {
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<GetResourceAuthInfoResponse>
) => {
if (!authInfo) {
throw new Error("No auth info to update");
throw new Error(t('authErrorNoUpdate'));
}
setAuthInfo((prev) => {

View File

@@ -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<GetSiteResponse>(serverSite);
const t = useTranslations();
const updateSite = (updatedSite: Partial<GetSiteResponse>) => {
if (!site) {
throw new Error("No site to update");
throw new Error(t('siteErrorNoUpdate'));
}
setSite((prev) => {
if (!prev) {

View File

@@ -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<GetUserResponse>(u);
const t = useTranslations();
const updateUser = (updatedUser: Partial<GetUserResponse>) => {
if (!user) {
throw new Error("No user to update");
throw new Error(t('userErrorNoUpdate'));
}
setUser((prev) => {
if (!prev) {