mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-29 18:13:47 +00:00
fix: landing page currency symbol not changing with locale
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.
This commit is contained in:
@@ -7,11 +7,28 @@ export function formatUptime(seconds: number): string {
|
|||||||
return `${minutes}m`;
|
return `${minutes}m`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatPrice(kopeks: number): string {
|
import i18next from 'i18next';
|
||||||
|
|
||||||
|
const LANG_CURRENCY_MAP: Record<string, { currency: string; locale: string; symbol: string }> = {
|
||||||
|
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;
|
const rubles = kopeks / 100;
|
||||||
return new Intl.NumberFormat('ru-RU', {
|
try {
|
||||||
|
return new Intl.NumberFormat(config.locale, {
|
||||||
style: 'currency',
|
style: 'currency',
|
||||||
currency: 'RUB',
|
currency: config.currency,
|
||||||
maximumFractionDigits: 0,
|
maximumFractionDigits: 0,
|
||||||
}).format(rubles);
|
}).format(rubles);
|
||||||
|
} catch {
|
||||||
|
return `${Math.round(rubles)} ${config.symbol}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user