forked from nathydre21/nepa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocalization.ts
More file actions
32 lines (28 loc) · 969 Bytes
/
localization.ts
File metadata and controls
32 lines (28 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { format } from 'date-fns';
import { enUS, fr, arSA } from 'date-fns/locale';
import i18n from '../i18n';
const locales: Record<string, any> = {
en: enUS,
fr: fr,
ar: arSA,
};
// Format date based on current language
export const formatDate = (date: Date, formatStr: string = 'PP') => {
const lang = i18n.language || 'en';
// Fallback to enUS if locale not found
const locale = locales[lang] || enUS;
return format(date, formatStr, { locale });
};
// Format currency (e.g., USD, EUR, SAR)
export const formatCurrency = (amount: number, currency: string = 'USD') => {
const lang = i18n.language || 'en';
return new Intl.NumberFormat(lang, {
style: 'currency',
currency: currency,
}).format(amount);
};
// Format numbers (decimals, separators)
export const formatNumber = (number: number, options?: Intl.NumberFormatOptions) => {
const lang = i18n.language || 'en';
return new Intl.NumberFormat(lang, options).format(number);
};