From 2d6815a88e49b4a2f19a00d1e1003780ee93dad7 Mon Sep 17 00:00:00 2001 From: Fringg Date: Thu, 23 Apr 2026 04:55:36 +0300 Subject: [PATCH] fix: landing page currency symbol not changing with locale MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit formatPrice() was hardcoded to ru-RU locale and RUB currency. Now it reads the current language from i18next and maps it to the appropriate currency (ru→RUB, en→USD, zh→CNY, fa→IRR). All consumers (QuickPurchase landing, GiftSubscription, admin) automatically get locale-aware currency formatting without any component-level changes. --- src/utils/format.ts | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/utils/format.ts b/src/utils/format.ts index f084109..ee42e2f 100644 --- a/src/utils/format.ts +++ b/src/utils/format.ts @@ -7,11 +7,28 @@ export function formatUptime(seconds: number): string { return `${minutes}m`; } -export function formatPrice(kopeks: number): string { +import i18next from 'i18next'; + +const LANG_CURRENCY_MAP: Record = { + ru: { currency: 'RUB', locale: 'ru-RU', symbol: '₽' }, + en: { currency: 'USD', locale: 'en-US', symbol: '$' }, + zh: { currency: 'CNY', locale: 'zh-CN', symbol: '¥' }, + fa: { currency: 'IRR', locale: 'fa-IR', symbol: '﷼' }, +}; + +const DEFAULT_CURRENCY = { currency: 'RUB', locale: 'ru-RU', symbol: '₽' }; + +export function formatPrice(kopeks: number, lang?: string): string { + const resolvedLang = lang || i18next.language || 'ru'; + const config = LANG_CURRENCY_MAP[resolvedLang] || DEFAULT_CURRENCY; const rubles = kopeks / 100; - return new Intl.NumberFormat('ru-RU', { - style: 'currency', - currency: 'RUB', - maximumFractionDigits: 0, - }).format(rubles); + try { + return new Intl.NumberFormat(config.locale, { + style: 'currency', + currency: config.currency, + maximumFractionDigits: 0, + }).format(rubles); + } catch { + return `${Math.round(rubles)} ${config.symbol}`; + } }