feat: web i18n (#1286)

This commit is contained in:
David Nguyen
2024-08-27 20:34:39 +09:00
committed by GitHub
parent 0829311214
commit 75c8772a02
294 changed files with 14846 additions and 2229 deletions

View File

@@ -3,6 +3,8 @@
import { useRouter } from 'next/navigation';
import { zodResolver } from '@hookform/resolvers/zod';
import { Trans, msg } from '@lingui/macro';
import { useLingui } from '@lingui/react';
import { useForm } from 'react-hook-form';
import { z } from 'zod';
@@ -49,8 +51,10 @@ export const ZClaimAccountFormSchema = z
export type TClaimAccountFormSchema = z.infer<typeof ZClaimAccountFormSchema>;
export const ClaimAccount = ({ defaultName, defaultEmail }: ClaimAccountProps) => {
const analytics = useAnalytics();
const { _ } = useLingui();
const { toast } = useToast();
const analytics = useAnalytics();
const router = useRouter();
const { mutateAsync: signup } = trpc.auth.signup.useMutation();
@@ -71,9 +75,10 @@ export const ClaimAccount = ({ defaultName, defaultEmail }: ClaimAccountProps) =
router.push(`/unverified-account`);
toast({
title: 'Registration Successful',
description:
'You have successfully registered. Please verify your account by clicking on the link you received in the email.',
title: _(msg`Registration Successful`),
description: _(
msg`You have successfully registered. Please verify your account by clicking on the link you received in the email.`,
),
duration: 5000,
});
@@ -84,15 +89,16 @@ export const ClaimAccount = ({ defaultName, defaultEmail }: ClaimAccountProps) =
} catch (error) {
if (error instanceof TRPCClientError && error.data?.code === 'BAD_REQUEST') {
toast({
title: 'An error occurred',
title: _(msg`An error occurred`),
description: error.message,
variant: 'destructive',
});
} else {
toast({
title: 'An unknown error occurred',
description:
'We encountered an unknown error while attempting to sign you up. Please try again later.',
title: _(msg`An unknown error occurred`),
description: _(
msg`We encountered an unknown error while attempting to sign you up. Please try again later.`,
),
variant: 'destructive',
});
}
@@ -109,9 +115,11 @@ export const ClaimAccount = ({ defaultName, defaultEmail }: ClaimAccountProps) =
control={form.control}
render={({ field }) => (
<FormItem>
<FormLabel>Name</FormLabel>
<FormLabel>
<Trans>Name</Trans>
</FormLabel>
<FormControl>
<Input {...field} placeholder="Enter your name" />
<Input {...field} placeholder={_(msg`Enter your name`)} />
</FormControl>
<FormMessage />
</FormItem>
@@ -122,9 +130,11 @@ export const ClaimAccount = ({ defaultName, defaultEmail }: ClaimAccountProps) =
control={form.control}
render={({ field }) => (
<FormItem className="mt-4">
<FormLabel>Email address</FormLabel>
<FormLabel>
<Trans>Email address</Trans>
</FormLabel>
<FormControl>
<Input {...field} placeholder="Enter your email" />
<Input {...field} placeholder={_(msg`Enter your email`)} />
</FormControl>
<FormMessage />
</FormItem>
@@ -135,9 +145,11 @@ export const ClaimAccount = ({ defaultName, defaultEmail }: ClaimAccountProps) =
control={form.control}
render={({ field }) => (
<FormItem className="mt-4">
<FormLabel>Set a password</FormLabel>
<FormLabel>
<Trans>Set a password</Trans>
</FormLabel>
<FormControl>
<PasswordInput {...field} placeholder="Pick a password" />
<PasswordInput {...field} placeholder={_(msg`Pick a password`)} />
</FormControl>
<FormMessage />
</FormItem>
@@ -145,7 +157,7 @@ export const ClaimAccount = ({ defaultName, defaultEmail }: ClaimAccountProps) =
/>
<Button type="submit" className="mt-6 w-full" loading={form.formState.isSubmitting}>
Claim account
<Trans>Claim account</Trans>
</Button>
</fieldset>
</form>