-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·95 lines (79 loc) · 2.5 KB
/
index.js
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*!
* pluralizer <https://github.com/derzunov/pluralizer>
*
* Copyright (c) 2016, Dmitry Erzunov.
* Licensed under the MIT License.
*/
'use strict';
var pluralFormTwoFormsDefault = function( number, titles ) {
var plural = number !== 1 ? 1 : 0;
return titles[plural]
};
var pluralFormTwoFormsSecond = function( number, titles ) {
var plural = number > 1 ? 1 : 0;
return titles[plural]
};
var pluralFormThreeFormsDefault = function( number, titles ) {
var cases = [2, 0, 1, 1, 1, 2];
return titles[number % 100 > 4 && number % 100 < 20 ? 2 : cases[number % 10 < 5 ? number % 10 : 5]];
};
var pluralFormSixFormsDefault = function( number, titles ) {
var plural = number === 0 ? 0 : number === 1 ? 1 : number === 2 ? 2 : number % 100 >= 3 && number % 100 <= 10 ? 3 : number % 100 >= 11 ? 4 : 5;
return titles[plural];
};
var pluralFormCs = function( number, titles ) {
var plural = number === 1 ? 0 : number >= 2 && number <= 4 ? 1 : 2;
return titles[ plural ];
};
var pluralFormPl = function( number, titles ) {
var plural = number === 1 ? 0 : number % 10 >= 2 && number % 10 <= 4 && (number % 100 < 10 || number % 100 >= 20) ? 1 : 2;
return titles[plural];
};
// Just for uniformity
var pluralFormOneForm = function( number, titles ) {
var plural = 0;
return titles[plural];
};
var pluralize = function( languageCode, number, titles ) {
switch( languageCode ) {
case 'ar-AR':
case 'ar':
return pluralFormSixFormsDefault( number, titles );
break;
case 'cs':
return pluralFormCs( number, titles );
break;
case 'pl':
return pluralFormPl( number, titles );
break;
case 'en-UK':
case 'en-US':
case 'en':
case 'de-DE':
case 'pt':
case 'de':
return pluralFormTwoFormsDefault( number, titles );
break;
case 'fr-FR':
case 'fr':
case 'pt-BR':
case 'br':
case 'oc':
case 'tr':
return pluralFormTwoFormsSecond( number, titles );
break;
case 'ru-RU':
case 'ru':
case 'be':
case 'bs':
case 'hr':
case 'sr':
case 'uk':
// Default ru-RU for example - 1 штука, 3 штуки, 5 штук
return pluralFormThreeFormsDefault( number, titles );
break;
default:
return pluralFormOneForm( number, titles );
}
};
module.exports = pluralize;