Completed
Push — master ( b895c6...fa6d7b )
by Rain
03:32
created

ar.js ➔ ... ➔ pluralForm   C

Complexity

Conditions 7
Paths 64

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
c 1
b 0
f 0
nc 64
dl 0
loc 3
rs 6.7272
nop 1
1
//! moment.js locale configuration
2
//! locale : Arabic [ar]
3
//! author : Abdel Said: https://github.com/abdelsaid
4
//! changes in months, weekdays: Ahmed Elkhatib
5
//! Native plural forms: forabi https://github.com/forabi
6
7
;(function (global, factory) {
8
   typeof exports === 'object' && typeof module !== 'undefined'
9
       && typeof require === 'function' ? factory(require('../moment')) :
10
   typeof define === 'function' && define.amd ? define(['../moment'], factory) :
11
   factory(global.moment)
12
}(this, function (moment) { 'use strict';
13
14
15
    var symbolMap = {
16
        '1': '١',
17
        '2': '٢',
18
        '3': '٣',
19
        '4': '٤',
20
        '5': '٥',
21
        '6': '٦',
22
        '7': '٧',
23
        '8': '٨',
24
        '9': '٩',
25
        '0': '٠'
26
    }, numberMap = {
27
        '١': '1',
28
        '٢': '2',
29
        '٣': '3',
30
        '٤': '4',
31
        '٥': '5',
32
        '٦': '6',
33
        '٧': '7',
34
        '٨': '8',
35
        '٩': '9',
36
        '٠': '0'
37
    }, pluralForm = function (n) {
38
        return n === 0 ? 0 : n === 1 ? 1 : n === 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5;
39
    }, plurals = {
40
        s : ['أقل من ثانية', 'ثانية واحدة', ['ثانيتان', 'ثانيتين'], '%d ثوان', '%d ثانية', '%d ثانية'],
41
        m : ['أقل من دقيقة', 'دقيقة واحدة', ['دقيقتان', 'دقيقتين'], '%d دقائق', '%d دقيقة', '%d دقيقة'],
42
        h : ['أقل من ساعة', 'ساعة واحدة', ['ساعتان', 'ساعتين'], '%d ساعات', '%d ساعة', '%d ساعة'],
43
        d : ['أقل من يوم', 'يوم واحد', ['يومان', 'يومين'], '%d أيام', '%d يومًا', '%d يوم'],
44
        M : ['أقل من شهر', 'شهر واحد', ['شهران', 'شهرين'], '%d أشهر', '%d شهرا', '%d شهر'],
45
        y : ['أقل من عام', 'عام واحد', ['عامان', 'عامين'], '%d أعوام', '%d عامًا', '%d عام']
46
    }, pluralize = function (u) {
47
        return function (number, withoutSuffix, string, isFuture) {
0 ignored issues
show
Unused Code introduced by
The parameter string is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter isFuture is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
48
            var f = pluralForm(number),
49
                str = plurals[u][pluralForm(number)];
50
            if (f === 2) {
51
                str = str[withoutSuffix ? 0 : 1];
52
            }
53
            return str.replace(/%d/i, number);
54
        };
55
    }, months = [
56
        'كانون الثاني يناير',
57
        'شباط فبراير',
58
        'آذار مارس',
59
        'نيسان أبريل',
60
        'أيار مايو',
61
        'حزيران يونيو',
62
        'تموز يوليو',
63
        'آب أغسطس',
64
        'أيلول سبتمبر',
65
        'تشرين الأول أكتوبر',
66
        'تشرين الثاني نوفمبر',
67
        'كانون الأول ديسمبر'
68
    ];
69
70
    var ar = moment.defineLocale('ar', {
71
        months : months,
72
        monthsShort : months,
73
        weekdays : 'الأحد_الإثنين_الثلاثاء_الأربعاء_الخميس_الجمعة_السبت'.split('_'),
74
        weekdaysShort : 'أحد_إثنين_ثلاثاء_أربعاء_خميس_جمعة_سبت'.split('_'),
75
        weekdaysMin : 'ح_ن_ث_ر_خ_ج_س'.split('_'),
76
        weekdaysParseExact : true,
77
        longDateFormat : {
78
            LT : 'HH:mm',
79
            LTS : 'HH:mm:ss',
80
            L : 'D/\u200FM/\u200FYYYY',
81
            LL : 'D MMMM YYYY',
82
            LLL : 'D MMMM YYYY HH:mm',
83
            LLLL : 'dddd D MMMM YYYY HH:mm'
84
        },
85
        meridiemParse: /ص|م/,
86
        isPM : function (input) {
87
            return 'م' === input;
88
        },
89
        meridiem : function (hour, minute, isLower) {
0 ignored issues
show
Unused Code introduced by
The parameter isLower is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter minute is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
90
            if (hour < 12) {
91
                return 'ص';
92
            } else {
93
                return 'م';
94
            }
95
        },
96
        calendar : {
97
            sameDay: '[اليوم عند الساعة] LT',
98
            nextDay: '[غدًا عند الساعة] LT',
99
            nextWeek: 'dddd [عند الساعة] LT',
100
            lastDay: '[أمس عند الساعة] LT',
101
            lastWeek: 'dddd [عند الساعة] LT',
102
            sameElse: 'L'
103
        },
104
        relativeTime : {
105
            future : 'بعد %s',
106
            past : 'منذ %s',
107
            s : pluralize('s'),
108
            m : pluralize('m'),
109
            mm : pluralize('m'),
110
            h : pluralize('h'),
111
            hh : pluralize('h'),
112
            d : pluralize('d'),
113
            dd : pluralize('d'),
114
            M : pluralize('M'),
115
            MM : pluralize('M'),
116
            y : pluralize('y'),
117
            yy : pluralize('y')
118
        },
119
        preparse: function (string) {
120
            return string.replace(/\u200f/g, '').replace(/[١٢٣٤٥٦٧٨٩٠]/g, function (match) {
121
                return numberMap[match];
122
            }).replace(/،/g, ',');
123
        },
124
        postformat: function (string) {
125
            return string.replace(/\d/g, function (match) {
126
                return symbolMap[match];
127
            }).replace(/,/g, '،');
128
        },
129
        week : {
130
            dow : 6, // Saturday is the first day of the week.
131
            doy : 12  // The week that contains Jan 1st is the first week of the year.
132
        }
133
    });
134
135
    return ar;
136
137
}));