update ar currency

This commit is contained in:
root
2026-06-02 01:45:05 -04:00
parent 8f57ca9d76
commit 29886c3397
9 changed files with 49 additions and 21 deletions
+28 -4
View File
@@ -61,13 +61,37 @@ export const PLAN_FEATURES: Record<string, string[]> = {
export type Locale = 'en' | 'fr' | 'ar'
export type SupportedCurrency = 'MAD'
export function formatCurrency(amount: number, _currency: SupportedCurrency = 'MAD', locale: Locale = 'en'): string {
function resolveLocale(locale?: Locale): Locale {
if (locale) return locale
const lang =
typeof globalThis === 'object' && 'document' in globalThis
? (globalThis as { document?: { documentElement?: { lang?: string } } }).document?.documentElement?.lang
: undefined
if (lang === 'en' || lang === 'fr' || lang === 'ar') {
return lang
}
return 'en'
}
export function getCurrencyLabel(locale?: Locale, _currency: SupportedCurrency = 'MAD'): string {
return resolveLocale(locale) === 'ar' ? 'درهم' : 'MAD'
}
export function formatCurrency(amount: number, _currency: SupportedCurrency = 'MAD', locale?: Locale): string {
const resolvedLocale = resolveLocale(locale)
const divisor = 100
const value = amount / divisor
const localeMap: Record<Locale, string> = { en: 'en-US', fr: 'fr-FR', ar: 'ar-MA' }
return new Intl.NumberFormat(localeMap[locale], {
style: 'currency',
currency: 'MAD',
const formattedValue = new Intl.NumberFormat(localeMap[resolvedLocale], {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
}).format(value)
const currencyLabel = getCurrencyLabel(resolvedLocale, _currency)
return resolvedLocale === 'en'
? `${currencyLabel} ${formattedValue}`
: `${formattedValue} ${currencyLabel}`
}