forked from joshswan/react-native-globalize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
157 lines (143 loc) · 5.04 KB
/
gulpfile.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*!
* React Native Globalize
*
* Copyright 2015-2019 Josh Swan
* Released under the MIT license
* https://github.com/joshswan/react-native-globalize/blob/master/LICENSE
*/
const gulp = require('gulp');
const filter = require('gulp-filter');
const merge = require('gulp-merge-json');
const path = require('path');
const Cldr = require('cldrjs');
const locales = [
'am', // Amharic
'ar', // Arabic
'bg', // Bulgarian
'bn', // Bengali
'ca', // Catalan
'cs', // Czech
'da', // Danish
'de', // German
'el', // Greek
'en', // English (United States)
'en-CA', // English Caanda
'en-GB', // English (Great Britain)
'en-AU',
'es', // Spanish
'es-419', // Spanish (Latin America & Caribbean)
'et', // Estonian
'fa', // Persian
'fi', // Finnish
'fil', // Filipino
'fr', // French
'gu', // Gujarati
'he', // Hebrew
'hi', // Hindi
'hr', // Croatian
'hu', // Hungarian
'id', // Indonesian
'it', // Italian
'ja', // Japanese
'kn', // Kannada
'ko', // Korean
'lt', // Lithuanian
'lv', // Latvian
'ml', // Malayalam
'mr', // Marathi
'ms', // Malay
'nb', // Norwegian
'nl', // Dutch
'pl', // Polish
'pt', // Portuguese
'pt-PT', // Portuguese (Portugal)
'ro', // Romanian
'ru', // Russian
'sk', // Slovak
'sl', // Slovenian
'sr', // Serbian
'sv', // Swedish
'sw', // Swahili
'ta', // Tamil
'te', // Telugu
'th', // Thai
'th-TH', // Thai
'tr', // Turkish
'uk', // Ukrainian
'vi', // Vietnamese
'vi-VN', // Vietnamese
'zh', // Chinese
'zh-Hans', // Chinese (Simplified)
'zh-Hant', // Chinese (Traditional)
];
const currencies = [
'CAD', // Canadian Dollar
'EUR', // Euro
'GBP', // British Pound
'USD', // US Dollar
'IDR', // Indonesian Rupiah
'AUD', // Australian dollar
'VND', // Vietnamese dong,
'THB', // Thai Baht
];
const files = ['ca-gregorian', 'currencies', 'dateFields', 'numbers', 'timeZoneNames', 'units'];
const supplemental = ['currencyData', 'likelySubtags', 'numberingSystems', 'ordinals', 'plurals', 'timeData', 'weekData'];
const cldrs = locales.map(x => new Cldr(x));
const languages = cldrs.map(x => x.attributes.language);
function removeUnusedLanguages(dict) {
if (dict) {
Object.keys(dict).forEach((key) => {
if (languages.indexOf(key) === -1) {
delete dict[key];
}
});
}
}
gulp.task('cldr', () => {
const cldrFilter = filter(file => (
(locales.indexOf(path.dirname(file.path).split(path.sep).pop()) > -1 && files.indexOf(path.basename(file.path, '.json')) > -1) || (path.dirname(file.path).split(path.sep).pop() === 'supplemental' && supplemental.indexOf(path.basename(file.path, '.json')) > -1)
));
return gulp.src(['./node_modules/cldr-data/supplemental/*.json', './node_modules/cldr-data/main/**/*.json'])
.pipe(cldrFilter)
.pipe(merge({
fileName: 'cldr.json',
edit: (obj) => {
if (obj.main) {
// For language files, grab the first language, and filter stuff out
const key = Object.keys(obj.main)[0];
const data = obj.main[key];
// Cut out unused dates.timeZoneNames.zone and dates.timeZoneNames.metazone data
if (data && data.dates && data.dates.timeZoneNames) {
data.dates.timeZoneNames.zone = {};
data.dates.timeZoneNames.metazone = {};
}
// Only include above currencies in each language
if (data && data.numbers && data.numbers.currencies) {
Object.keys(data.numbers.currencies).forEach((code) => {
if (currencies.indexOf(code) === -1) {
delete data.numbers.currencies[code];
}
});
}
}
// Cut out unused languages from our supplemental files
if (obj.supplemental) {
const languageDictKeys = ['plurals-type-ordinal', 'plurals-type-cardinal'];
languageDictKeys.forEach((languageDictKey) => {
removeUnusedLanguages(obj.supplemental[languageDictKey]);
});
// Only include currencies above
if (obj.supplemental.currencyData) {
delete obj.supplemental.currencyData.region;
Object.keys(obj.supplemental.currencyData.fractions).forEach((code) => {
if (currencies.indexOf(code) === -1 && code.toLowerCase() !== 'default') {
delete obj.supplemental.currencyData.fractions[code];
}
});
}
}
return obj;
},
}))
.pipe(gulp.dest('lib'));
});