update ar currency
This commit is contained in:
@@ -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}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user