From 4efa45b319f7fba6414b154e3470b7e4d2497fe6 Mon Sep 17 00:00:00 2001 From: Amir Moghani Date: Sat, 13 Jun 2026 11:52:08 +0330 Subject: [PATCH] feat: add dynamic year based on locale (Gregorian for EN, Persian for FA) --- public/locales/en/authentication.json | 4 ++-- public/locales/fa/authentication.json | 4 ++-- .../AuthenticationSteps/LanguageSwitcher.tsx | 3 ++- src/utils/getYear.ts | 11 +++++++++++ 4 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 src/utils/getYear.ts diff --git a/public/locales/en/authentication.json b/public/locales/en/authentication.json index 31375ae..77743aa 100644 --- a/public/locales/en/authentication.json +++ b/public/locales/en/authentication.json @@ -11,7 +11,7 @@ "googleAuthenticationFailed": "Login with google failed", "persian": "Persian (Fa)", "english": "English (En)", - "accountInfo": "Harmony Account - 2025" + "accountInfo": "Harmony Account - {{year}}" }, "verify": { "verify": "Verify", @@ -67,4 +67,4 @@ "redirectingTo": "Redirecting to", "redirecting": "Redirecting..." } -} +} \ No newline at end of file diff --git a/public/locales/fa/authentication.json b/public/locales/fa/authentication.json index 21eb655..883bc71 100644 --- a/public/locales/fa/authentication.json +++ b/public/locales/fa/authentication.json @@ -11,7 +11,7 @@ "googleAuthenticationFailed": "ورود با گوگل با خطا مواجه شد", "persian": "فارسی (Fa)", "english": "انگلیسی (En)", - "accountInfo": "۱۴۰۴-هارمونی اکانت" + "accountInfo": "{{year}}-هارمونی اکانت" }, "verify": { "verify": "اعتبارسنجی", @@ -67,4 +67,4 @@ "redirectingTo": "در حال انتقال به", "redirecting": "درحال انتقال..." } -} +} \ No newline at end of file diff --git a/src/features/authentication/components/AuthenticationSteps/LanguageSwitcher.tsx b/src/features/authentication/components/AuthenticationSteps/LanguageSwitcher.tsx index cbfc892..aaf0ec9 100644 --- a/src/features/authentication/components/AuthenticationSteps/LanguageSwitcher.tsx +++ b/src/features/authentication/components/AuthenticationSteps/LanguageSwitcher.tsx @@ -2,6 +2,7 @@ import { Box, Typography, MenuItem, Select, Stack } from '@mui/material'; import { Icon } from '@harmony/kit'; import { Global } from 'iconsax-react'; import { useTranslation } from 'react-i18next'; +import { getYear } from '@/utils/getYear'; export default function LanguageAccountBar() { const { t, i18n } = useTranslation('authentication'); @@ -25,7 +26,7 @@ export default function LanguageAccountBar() { > - {t('loginForm.accountInfo')} + {t('loginForm.accountInfo', { year: getYear(i18n.language) })} diff --git a/src/utils/getYear.ts b/src/utils/getYear.ts new file mode 100644 index 0000000..6a80c43 --- /dev/null +++ b/src/utils/getYear.ts @@ -0,0 +1,11 @@ +export const getYear = (lang: string) => { + if (lang === 'fa') { + return new Intl.DateTimeFormat('fa-IR-u-ca-persian', { + year: 'numeric', + }).format(new Date()); + } + + return new Intl.DateTimeFormat('en-US', { + year: 'numeric', + }).format(new Date()); +}; \ No newline at end of file