From 341d5f3b3ed5052f1e6757253258614648c1ccbb Mon Sep 17 00:00:00 2001 From: Janderson Souza Matias Date: Mon, 15 Jan 2024 21:19:23 -0300 Subject: [PATCH] translate login page to nepali --- src/i18n/index.ts | 2 +- src/i18n/langs/en.ts | 9 ++++++++- src/i18n/langs/np.ts | 8 ++++++++ src/pages/Login/index.tsx | 18 +++++++++++++----- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/i18n/index.ts b/src/i18n/index.ts index 452148b..9d3dba4 100644 --- a/src/i18n/index.ts +++ b/src/i18n/index.ts @@ -15,7 +15,7 @@ export const resources: { i18n.use(initReactI18next).init({ compatibilityJSON: 'v3', resources, - fallbackLng: 'en', + fallbackLng: import.meta.env.VITE_COUNTRY === 'np' ? 'np' : 'en', interpolation: { escapeValue: false, }, diff --git a/src/i18n/langs/en.ts b/src/i18n/langs/en.ts index e7ad39c..8170d44 100644 --- a/src/i18n/langs/en.ts +++ b/src/i18n/langs/en.ts @@ -23,7 +23,14 @@ const enTranslation = { complete: 'Complete', incomplete: 'Incomplete', }, - + Login: { + email: 'E-mail', + 'request-button': 'Request one-time login code', + 'verify-button': 'Verify code', + 'invalid-email': 'Invalid email', + 'invalid-code': 'Invalid code', + 'code-label': 'Enter the code we sent to your email', + }, Navbar: { logout: 'Log out', settings: 'Settings', diff --git a/src/i18n/langs/np.ts b/src/i18n/langs/np.ts index 7a99d0c..2511aa3 100644 --- a/src/i18n/langs/np.ts +++ b/src/i18n/langs/np.ts @@ -23,6 +23,14 @@ const npTranslation = { complete: 'पूर्ण', incomplete: 'अपूर्ण', }, + Login: { + email: 'ई-मेल', + 'request-button': 'एक-पटकको लग-इन कोड माग गर्नुहोस्', + 'verify-button': 'कोड प्रमाणित गर्नुहोस्', + 'invalid-email': 'अमान्य इमेल', + 'invalid-code': 'अमान्य कोड', + 'code-label': 'तपाईंको ईमेलमा पठाइएको कोड प्रविष्ट गर्नुहोस्', + }, Navbar: { dashboard: 'मुख्य पृष्ठ', questionnaire: 'प्रश्नावली', diff --git a/src/pages/Login/index.tsx b/src/pages/Login/index.tsx index 69d04be..ddb7cd9 100644 --- a/src/pages/Login/index.tsx +++ b/src/pages/Login/index.tsx @@ -17,6 +17,7 @@ import { } from '@chakra-ui/react'; import React, { useContext, useState } from 'react'; import { useForm, SubmitHandler, Controller } from 'react-hook-form'; +import { useTranslation } from 'react-i18next'; import { CloseButton } from 'react-toastify/dist/components'; const defaultValues = { @@ -33,6 +34,7 @@ const Login: React.FC = () => { const [error, setError] = useState(''); const [showOTP, setShowOTP] = useState(false); const [code, setCode] = useState(''); + const { t } = useTranslation(); const handleLogin: SubmitHandler = async ({ email }) => { try { @@ -45,9 +47,9 @@ const Login: React.FC = () => { } } catch (err: any) { if (showOTP) { - setError('Invalid code'); + setError(t('Login.invalid-code') || ''); } else { - setError('Invalid email'); + setError(t('Login.invalid-email') || ''); } setCode(''); } @@ -75,7 +77,13 @@ const Login: React.FC = () => { rules={{ required: true }} name="email" render={({ field, fieldState: { error } }) => ( - + )} /> {error && ( @@ -86,7 +94,7 @@ const Login: React.FC = () => { )} {showOTP && ( - Enter the code we sent to your email + {t('Login.code-labelकोच डिजिटल एनपी')} @@ -108,7 +116,7 @@ const Login: React.FC = () => { onClick={handleSubmit(handleLogin)} isDisabled={showOTP && code.length < 4} > - {showOTP ? 'Verify code' : 'Send OTP code'} + {showOTP ? t('Login.verify-button') : t('Login.request-button')} )}