Skip to content

Commit 9968df4

Browse files
Add persian locale (#6560)
Co-authored-by: Alexey Umanskiy <[email protected]>
1 parent b15cea2 commit 9968df4

File tree

3 files changed

+408
-0
lines changed

3 files changed

+408
-0
lines changed

Diff for: src/chronos/i18n/fa.ts

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
//! moment.js locale configuration
2+
//! locale : Persian [fa]
3+
//! author : Meysam Bahadori: https://github.com/MeysamBahadori
4+
5+
import { LocaleData } from '../locale/locale.class';
6+
7+
const symbolMap: {[key: string]: string} = {
8+
1: '١',
9+
2: '٢',
10+
3: '٣',
11+
4: '٤',
12+
5: '٥',
13+
6: '٦',
14+
7: '٧',
15+
8: '٨',
16+
9: '٩',
17+
0: '٠'
18+
};
19+
20+
const numberMap: {[key: string]: string} = {
21+
'١': '1',
22+
'٢': '2',
23+
'٣': '3',
24+
'٤': '4',
25+
'٥': '5',
26+
'٦': '6',
27+
'٧': '7',
28+
'٨': '8',
29+
'٩': '9',
30+
'٠': '0'
31+
};
32+
33+
const pluralForm = function (num: number): number {
34+
return num === 0 ? 0 : num === 1 ? 1 : num === 2 ? 2 : num % 100 >= 3 && num % 100 <= 10 ? 3 : num % 100 >= 11 ? 4 : 5;
35+
};
36+
37+
var plurals : {[key: string]: [string, string, [string, string], string, string, string]} = {
38+
s: ['کمتر از یک ثانیه', 'یک ثانیه', ['دو ثانیه', 'دو ثانیه'], '%d ثانیه', '%d ثانیه', '%d ثانیه'],
39+
m: ['کمتر از یک دقیقه', 'یک دقیقه', ['دو دقیقه', 'دو دقیقه'], '%d دقیقه', '%d دقیقه', '%d دقیقه'],
40+
h: ['کمتر از یک ساعت', 'یک ساعت', ['دو ساعت', 'دو ساعت'], '%d ساعت', '%d ساعت', '%d ساعت'],
41+
d: ['کمتر از یک روز', 'یک روز', ['دو روز', 'دو روز'], '%d روز', '%d روز', '%d روز'],
42+
M: ['کمتر از یک ماه', 'یک ماه', ['دو ماه', 'دو ماه'], '%d ماه', '%d ماه', '%d ماه'],
43+
y: ['کمتر از یک سال', 'یک سال', ['دو سال', 'دو سال'], '%d سال', '%d سال', '%d سال']
44+
};
45+
46+
const pluralize = function (u: string) {
47+
return function (num: number, withoutSuffix: boolean): string {
48+
const f = pluralForm(num);
49+
let str = plurals[u][pluralForm(num)];
50+
if (f === 2) {
51+
str = str[withoutSuffix ? 0 : 1];
52+
}
53+
54+
return (str as string).replace(/%d/i, num.toString());
55+
};
56+
};
57+
58+
const months: string[] = [
59+
'ژانویه',
60+
'فوریه',
61+
'مارس',
62+
'آوریل',
63+
'می',
64+
'ژوئن',
65+
'جولای',
66+
'آگوست',
67+
'سپتامبر',
68+
'اکتبر',
69+
'نوامبر',
70+
'دسامبر'
71+
];
72+
73+
export const faLocale: LocaleData = {
74+
abbr: 'fa',
75+
months: months,
76+
monthsShort: months,
77+
weekdays: 'یکشنبه_دوشنبه_سه شنبه_چهارشنبه_پنج شنبه_جمعه_شنبه'.split('_'),
78+
weekdaysShort: 'یکشنبه_دو‌شنبه_سه‌شنبه_چهار‌شنبه_پنج‌شنبه_جمعه_شنبه'.split('_'),
79+
weekdaysMin: 'ی_د_س_چ_پ_ج_ش'.split('_'),
80+
weekdaysParseExact: true,
81+
longDateFormat: {
82+
LT: 'HH:mm',
83+
LTS: 'HH:mm:ss',
84+
L: 'D/\u200FM/\u200FYYYY',
85+
LL: 'D MMMM YYYY',
86+
LLL: 'D MMMM YYYY HH:mm',
87+
LLLL: 'dddd D MMMM YYYY HH:mm'
88+
},
89+
meridiemParse: /ص|م/,
90+
isPM(input) {
91+
return 'م' === input;
92+
},
93+
meridiem(hour, minute, isLower) {
94+
if (hour < 12) {
95+
return 'ص';
96+
} else {
97+
return 'م';
98+
}
99+
},
100+
calendar: {
101+
sameDay: '[امروز در ساعت] LT',
102+
nextDay: '[فردا در ساعت] LT',
103+
nextWeek: 'dddd [در ساعت] LT',
104+
lastDay: '[دیروز در ساعت] LT',
105+
lastWeek: 'dddd [در ساعت] LT',
106+
sameElse: 'L'
107+
},
108+
relativeTime: {
109+
future: 'بعد %s',
110+
past: 'پیش %s',
111+
s: pluralize('s'),
112+
ss: pluralize('s'),
113+
m: pluralize('m'),
114+
mm: pluralize('m'),
115+
h: pluralize('h'),
116+
hh: pluralize('h'),
117+
d: pluralize('d'),
118+
dd: pluralize('d'),
119+
M: pluralize('M'),
120+
MM: pluralize('M'),
121+
y: pluralize('y'),
122+
yy: pluralize('y')
123+
},
124+
preparse(str: string): string {
125+
return str.replace(/[١٢٣٤٥٦٧٨٩٠]/g, function (match) {
126+
return numberMap[match];
127+
}).replace(/،/g, ',');
128+
},
129+
postformat(str: string) {
130+
return str.replace(/\d/g, function (match) {
131+
return symbolMap[match];
132+
}).replace(/,/g, '،');
133+
},
134+
week: {
135+
dow: 6, // Saturday is the first day of the week.
136+
doy: 80 // The week that contains March 21th is the first week of the year.
137+
}
138+
};

Diff for: src/chronos/public_api.ts

+1
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,4 @@ export { trLocale } from './i18n/tr';
8080
export { ukLocale } from './i18n/uk';
8181
export { viLocale } from './i18n/vi';
8282
export { zhCnLocale } from './i18n/zh-cn';
83+
export { faLocale } from './i18n/fa';

0 commit comments

Comments
 (0)