-
-
Notifications
You must be signed in to change notification settings - Fork 165
/
test.js
303 lines (286 loc) · 17.2 KB
/
test.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
// Tests locale files
// Use --all to see all missed keys
const languageCodes = [
{"code":"ab","name":"Abkhaz","nativeName":"аҧсуа"},
{"code":"aa","name":"Afar","nativeName":"Afaraf"},
{"code":"af","name":"Afrikaans","nativeName":"Afrikaans"},
{"code":"ak","name":"Akan","nativeName":"Akan"},
{"code":"sq","name":"Albanian","nativeName":"Shqip"},
{"code":"am","name":"Amharic","nativeName":"አማርኛ"},
{"code":"ar","name":"Arabic","nativeName":"العربية"},
{"code":"an","name":"Aragonese","nativeName":"Aragonés"},
{"code":"hy","name":"Armenian","nativeName":"Հայերեն"},
{"code":"as","name":"Assamese","nativeName":"অসমীয়া"},
{"code":"av","name":"Avaric","nativeName":"авар мацӀ, магӀарул мацӀ"},
{"code":"ae","name":"Avestan","nativeName":"avesta"},
{"code":"ay","name":"Aymara","nativeName":"aymar aru"},
{"code":"az","name":"Azerbaijani","nativeName":"azərbaycan dili"},
{"code":"bm","name":"Bambara","nativeName":"bamanankan"},
{"code":"ba","name":"Bashkir","nativeName":"башҡорт теле"},
{"code":"eu","name":"Basque","nativeName":"euskara, euskera"},
{"code":"be","name":"Belarusian","nativeName":"Беларуская"},
{"code":"bn","name":"Bengali","nativeName":"বাংলা"},
{"code":"bh","name":"Bihari","nativeName":"भोजपुरी"},
{"code":"bi","name":"Bislama","nativeName":"Bislama"},
{"code":"bs","name":"Bosnian","nativeName":"bosanski jezik"},
{"code":"br","name":"Breton","nativeName":"brezhoneg"},
{"code":"bg","name":"Bulgarian","nativeName":"български език"},
{"code":"my","name":"Burmese","nativeName":"ဗမာစာ"},
{"code":"ca","name":"Catalan; Valencian","nativeName":"Català"},
{"code":"ch","name":"Chamorro","nativeName":"Chamoru"},
{"code":"ce","name":"Chechen","nativeName":"нохчийн мотт"},
{"code":"ny","name":"Chichewa; Chewa; Nyanja","nativeName":"chiCheŵa, chinyanja"},
{"code":"zh","name":"Chinese","nativeName":"中文 (Zhōngwén), 汉语, 漢語"},
{"code":"zh_CN","name":"Chinese (Simplified)","nativeName":"中文 (Zhōngwén), 汉语, 漢語"},
{"code":"zh_TW","name":"Chinese (Traditional)","nativeName":"中文 (Zhōngwén), 汉语, 漢語"},
{"code":"cv","name":"Chuvash","nativeName":"чӑваш чӗлхи"},
{"code":"kw","name":"Cornish","nativeName":"Kernewek"},
{"code":"co","name":"Corsican","nativeName":"corsu, lingua corsa"},
{"code":"cr","name":"Cree","nativeName":"ᓀᐦᐃᔭᐍᐏᐣ"},
{"code":"hr","name":"Croatian","nativeName":"hrvatski"},
{"code":"cs","name":"Czech","nativeName":"česky, čeština"},
{"code":"da","name":"Danish","nativeName":"dansk"},
{"code":"dv","name":"Divehi; Dhivehi; Maldivian;","nativeName":"ދިވެހި"},
{"code":"nl","name":"Dutch","nativeName":"Nederlands, Vlaams"},
{"code":"en","name":"English","nativeName":"English"},
{"code":"eo","name":"Esperanto","nativeName":"Esperanto"},
{"code":"et","name":"Estonian","nativeName":"eesti, eesti keel"},
{"code":"ee","name":"Ewe","nativeName":"Eʋegbe"},
{"code":"fo","name":"Faroese","nativeName":"føroyskt"},
{"code":"fj","name":"Fijian","nativeName":"vosa Vakaviti"},
{"code":"fi","name":"Finnish","nativeName":"suomi, suomen kieli"},
{"code":"fr","name":"French","nativeName":"français, langue française"},
{"code":"ff","name":"Fula; Fulah; Pulaar; Pular","nativeName":"Fulfulde, Pulaar, Pular"},
{"code":"gl","name":"Galician","nativeName":"Galego"},
{"code":"ka","name":"Georgian","nativeName":"ქართული"},
{"code":"de","name":"German","nativeName":"Deutsch"},
{"code":"el","name":"Greek, Modern","nativeName":"Ελληνικά"},
{"code":"gn","name":"Guaraní","nativeName":"Avañeẽ"},
{"code":"gu","name":"Gujarati","nativeName":"ગુજરાતી"},
{"code":"ht","name":"Haitian; Haitian Creole","nativeName":"Kreyòl ayisyen"},
{"code":"ha","name":"Hausa","nativeName":"Hausa, هَوُسَ"},
{"code":"he","name":"Hebrew (modern)","nativeName":"עברית"},
{"code":"hz","name":"Herero","nativeName":"Otjiherero"},
{"code":"hi","name":"Hindi","nativeName":"हिन्दी, हिंदी"},
{"code":"ho","name":"Hiri Motu","nativeName":"Hiri Motu"},
{"code":"hu","name":"Hungarian","nativeName":"Magyar"},
{"code":"ia","name":"Interlingua","nativeName":"Interlingua"},
{"code":"id","name":"Indonesian","nativeName":"Bahasa Indonesia"},
{"code":"ie","name":"Interlingue","nativeName":"Originally called Occidental; then Interlingue after WWII"},
{"code":"ga","name":"Irish","nativeName":"Gaeilge"},
{"code":"ig","name":"Igbo","nativeName":"Asụsụ Igbo"},
{"code":"ik","name":"Inupiaq","nativeName":"Iñupiaq, Iñupiatun"},
{"code":"io","name":"Ido","nativeName":"Ido"},
{"code":"is","name":"Icelandic","nativeName":"Íslenska"},
{"code":"it","name":"Italian","nativeName":"Italiano"},
{"code":"iu","name":"Inuktitut","nativeName":"ᐃᓄᒃᑎᑐᑦ"},
{"code":"ja","name":"Japanese","nativeName":"日本語 (にほんご/にっぽんご)"},
{"code":"jv","name":"Javanese","nativeName":"basa Jawa"},
{"code":"kl","name":"Kalaallisut, Greenlandic","nativeName":"kalaallisut, kalaallit oqaasii"},
{"code":"kn","name":"Kannada","nativeName":"ಕನ್ನಡ"},
{"code":"kr","name":"Kanuri","nativeName":"Kanuri"},
{"code":"ks","name":"Kashmiri","nativeName":"कश्मीरी, كشميري"},
{"code":"kk","name":"Kazakh","nativeName":"Қазақ тілі"},
{"code":"km","name":"Khmer","nativeName":"ភាសាខ្មែរ"},
{"code":"ki","name":"Kikuyu, Gikuyu","nativeName":"Gĩkũyũ"},
{"code":"rw","name":"Kinyarwanda","nativeName":"Ikinyarwanda"},
{"code":"ky","name":"Kirghiz, Kyrgyz","nativeName":"кыргыз тили"},
{"code":"kv","name":"Komi","nativeName":"коми кыв"},
{"code":"kg","name":"Kongo","nativeName":"KiKongo"},
{"code":"ko","name":"Korean","nativeName":"한국어 (韓國語), 조선말 (朝鮮語)"},
{"code":"ku","name":"Kurdish","nativeName":"Kurdî, كوردی"},
{"code":"kj","name":"Kwanyama, Kuanyama","nativeName":"Kuanyama"},
{"code":"la","name":"Latin","nativeName":"latine, lingua latina"},
{"code":"lb","name":"Luxembourgish, Letzeburgesch","nativeName":"Lëtzebuergesch"},
{"code":"lg","name":"Luganda","nativeName":"Luganda"},
{"code":"li","name":"Limburgish, Limburgan, Limburger","nativeName":"Limburgs"},
{"code":"ln","name":"Lingala","nativeName":"Lingála"},
{"code":"lo","name":"Lao","nativeName":"ພາສາລາວ"},
{"code":"lt","name":"Lithuanian","nativeName":"lietuvių kalba"},
{"code":"lu","name":"Luba-Katanga","nativeName":""},
{"code":"lv","name":"Latvian","nativeName":"latviešu valoda"},
{"code":"gv","name":"Manx","nativeName":"Gaelg, Gailck"},
{"code":"mk","name":"Macedonian","nativeName":"македонски јазик"},
{"code":"mg","name":"Malagasy","nativeName":"Malagasy fiteny"},
{"code":"ms","name":"Malay","nativeName":"bahasa Melayu, بهاس ملايو"},
{"code":"ml","name":"Malayalam","nativeName":"മലയാളം"},
{"code":"mt","name":"Maltese","nativeName":"Malti"},
{"code":"mi","name":"Māori","nativeName":"te reo Māori"},
{"code":"mr","name":"Marathi (Marāṭhī)","nativeName":"मराठी"},
{"code":"mh","name":"Marshallese","nativeName":"Kajin M̧ajeļ"},
{"code":"mn","name":"Mongolian","nativeName":"монгол"},
{"code":"na","name":"Nauru","nativeName":"Ekakairũ Naoero"},
{"code":"nv","name":"Navajo, Navaho","nativeName":"Diné bizaad, Dinékʼehǰí"},
{"code":"nb","name":"Norwegian Bokmål","nativeName":"Norsk bokmål"},
{"code":"nd","name":"North Ndebele","nativeName":"isiNdebele"},
{"code":"ne","name":"Nepali","nativeName":"नेपाली"},
{"code":"ng","name":"Ndonga","nativeName":"Owambo"},
{"code":"nn","name":"Norwegian Nynorsk","nativeName":"Norsk nynorsk"},
{"code":"no","name":"Norwegian","nativeName":"Norsk"},
{"code":"ii","name":"Nuosu","nativeName":"ꆈꌠ꒿ Nuosuhxop"},
{"code":"nr","name":"South Ndebele","nativeName":"isiNdebele"},
{"code":"oc","name":"Occitan","nativeName":"Occitan"},
{"code":"oj","name":"Ojibwe, Ojibwa","nativeName":"ᐊᓂᔑᓈᐯᒧᐎᓐ"},
{"code":"cu","name":"Old Church Slavonic, Church Slavic, Church Slavonic, Old Bulgarian, Old Slavonic","nativeName":"ѩзыкъ словѣньскъ"},
{"code":"om","name":"Oromo","nativeName":"Afaan Oromoo"},
{"code":"or","name":"Oriya","nativeName":"ଓଡ଼ିଆ"},
{"code":"os","name":"Ossetian, Ossetic","nativeName":"ирон æвзаг"},
{"code":"pa","name":"Panjabi, Punjabi","nativeName":"ਪੰਜਾਬੀ, پنجابی"},
{"code":"pi","name":"Pāli","nativeName":"पाऴि"},
{"code":"fa","name":"Persian","nativeName":"فارسی"},
{"code":"pl","name":"Polish","nativeName":"polski"},
{"code":"ps","name":"Pashto, Pushto","nativeName":"پښتو"},
{"code":"pt","name":"Portuguese","nativeName":"Português"},
{"code":"pt_BR","name":"Portuguese (Brazil)","nativeName":"Português do Brasil"},
{"code":"qu","name":"Quechua","nativeName":"Runa Simi, Kichwa"},
{"code":"rm","name":"Romansh","nativeName":"rumantsch grischun"},
{"code":"rn","name":"Kirundi","nativeName":"kiRundi"},
{"code":"ro","name":"Romanian, Moldavian, Moldovan","nativeName":"română"},
{"code":"ru","name":"Russian","nativeName":"русский язык"},
{"code":"sa","name":"Sanskrit (Saṁskṛta)","nativeName":"संस्कृतम्"},
{"code":"sc","name":"Sardinian","nativeName":"sardu"},
{"code":"sd","name":"Sindhi","nativeName":"सिन्धी, سنڌي، سندھی"},
{"code":"se","name":"Northern Sami","nativeName":"Davvisámegiella"},
{"code":"sm","name":"Samoan","nativeName":"gagana faa Samoa"},
{"code":"sg","name":"Sango","nativeName":"yângâ tî sängö"},
{"code":"sr","name":"Serbian","nativeName":"српски језик"},
{"code":"gd","name":"Scottish Gaelic; Gaelic","nativeName":"Gàidhlig"},
{"code":"sn","name":"Shona","nativeName":"chiShona"},
{"code":"si","name":"Sinhala, Sinhalese","nativeName":"සිංහල"},
{"code":"sk","name":"Slovak","nativeName":"slovenčina"},
{"code":"sl","name":"Slovene","nativeName":"slovenščina"},
{"code":"so","name":"Somali","nativeName":"Soomaaliga, af Soomaali"},
{"code":"st","name":"Southern Sotho","nativeName":"Sesotho"},
{"code":"es","name":"Spanish; Castilian","nativeName":"español, castellano"},
{"code":"su","name":"Sundanese","nativeName":"Basa Sunda"},
{"code":"sw","name":"Swahili","nativeName":"Kiswahili"},
{"code":"ss","name":"Swati","nativeName":"SiSwati"},
{"code":"sv","name":"Swedish","nativeName":"svenska"},
{"code":"ta","name":"Tamil","nativeName":"தமிழ்"},
{"code":"te","name":"Telugu","nativeName":"తెలుగు"},
{"code":"tg","name":"Tajik","nativeName":"тоҷикӣ, toğikī, تاجیکی"},
{"code":"th","name":"Thai","nativeName":"ไทย"},
{"code":"ti","name":"Tigrinya","nativeName":"ትግርኛ"},
{"code":"bo","name":"Tibetan Standard, Tibetan, Central","nativeName":"བོད་ཡིག"},
{"code":"tk","name":"Turkmen","nativeName":"Türkmen, Түркмен"},
{"code":"tl","name":"Tagalog","nativeName":"Wikang Tagalog, ᜏᜒᜃᜅ᜔ ᜆᜄᜎᜓᜄ᜔"},
{"code":"tn","name":"Tswana","nativeName":"Setswana"},
{"code":"to","name":"Tonga (Tonga Islands)","nativeName":"faka Tonga"},
{"code":"tr","name":"Turkish","nativeName":"Türkçe"},
{"code":"ts","name":"Tsonga","nativeName":"Xitsonga"},
{"code":"tt","name":"Tatar","nativeName":"татарча, tatarça, تاتارچا"},
{"code":"tw","name":"Twi","nativeName":"Twi"},
{"code":"ty","name":"Tahitian","nativeName":"Reo Tahiti"},
{"code":"ug","name":"Uighur, Uyghur","nativeName":"Uyƣurqə, ئۇيغۇرچە"},
{"code":"uk","name":"Ukrainian","nativeName":"українська"},
{"code":"ur","name":"Urdu","nativeName":"اردو"},
{"code":"uz","name":"Uzbek","nativeName":"zbek, Ўзбек, أۇزبېك"},
{"code":"ve","name":"Venda","nativeName":"Tshivenḓa"},
{"code":"vi","name":"Vietnamese","nativeName":"Tiếng Việt"},
{"code":"vo","name":"Volapük","nativeName":"Volapük"},
{"code":"wa","name":"Walloon","nativeName":"Walon"},
{"code":"cy","name":"Welsh","nativeName":"Cymraeg"},
{"code":"wo","name":"Wolof","nativeName":"Wollof"},
{"code":"fy","name":"Western Frisian","nativeName":"Frysk"},
{"code":"xh","name":"Xhosa","nativeName":"isiXhosa"},
{"code":"yi","name":"Yiddish","nativeName":"ייִדיש"},
{"code":"yo","name":"Yoruba","nativeName":"Yorùbá"},
{"code":"za","name":"Zhuang, Chuang","nativeName":"Saɯ cueŋƅ, Saw cuengh"}
];
const fs = require('fs');
const path = require('path');
const validKey = /^[a-zA-Z0-9_@]+$/;
const placeholdersRegex = /\$[a-zA-Z0-9_@]+\$/g;
const validFieldKeys = ['name', 'message', 'description', 'example', 'note', 'placeholders'];
const locales =
fs.readdirSync(path.join(__dirname, '_locales'), { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name);
const englishLocale = JSON.parse(fs.readFileSync(path.join(__dirname, '_locales', 'en', 'messages.json')));
const englishLocaleArray = Object.keys(englishLocale);
let errors = false;
for(let localeName of locales) {
let locale;
try {
locale = JSON.parse(fs.readFileSync(path.join(__dirname, '_locales', localeName, 'messages.json')));
} catch(e) {
console.error(`❌ (Critical) Error parsing _locales/${localeName}/messages.json`, e);
errors = true;
continue;
}
if(localeName !== 'en') {
let array = Object.keys(locale);
let diff = englishLocaleArray.length - array.length;
if(diff !== 0) {
if(diff < 10 || process.argv.includes('--all')) {
let missing = englishLocaleArray.filter(key => !array.includes(key));
console.log(`❌ Missing ${diff} keys in _locales/${localeName}/messages.json (${languageCodes.find(l => l.code === localeName)?.name}): ${missing.join(', ')}`);
} else {
console.log(`❌ Missing ${diff} keys in _locales/${localeName}/messages.json (${languageCodes.find(l => l.code === localeName)?.name})`);
}
} else {
console.log(`✅ All keys present in _locales/${localeName}/messages.json (${languageCodes.find(l => l.code === localeName)?.name})`);
}
}
let keys = Object.keys(locale);
for(let key of keys) {
if(!englishLocale[key]) {
console.error(`❌ Key "${key}" is not present in English for _locales/${localeName}/messages.json`);
errors = true;
}
if(!validKey.test(key)) {
console.error(`❌ Invalid key "${key}" in _locales/${localeName}/messages.json`);
errors = true;
}
if(key.length > 80) {
console.error(`❌ Key "${key}" is too long in _locales/${localeName}/messages.json`);
errors = true;
}
}
if(!locale.ext_description) {
console.error(`❌ Missing "ext_description" in _locales/${localeName}/messages.json`);
errors = true;
}
if(locale.ext_description.length > 132) {
console.error(`❌ "ext_description" is too long in _locales/${localeName}/messages.json`);
errors = true;
}
for(let fieldName in locale) {
let field = locale[fieldName];
let keys = Object.keys(field);
for(let key of keys) {
if(!validFieldKeys.includes(key)) {
console.error(`❌ Invalid key "${key}" on "${fieldName}" in _locales/${localeName}/messages.json`);
errors = true;
}
}
if(typeof field.message !== 'string') {
console.error(`❌ Missing "message" on "${fieldName}" in _locales/${localeName}/messages.json`);
errors = true;
}
let placeholders = field.message.match(placeholdersRegex);
if(placeholders) {
if(!field.placeholders) {
console.error(`❌ Missing "placeholders" on "${fieldName}" in _locales/${localeName}/messages.json`);
errors = true;
} else {
placeholders = placeholders.map(placeholder => placeholder.slice(1, -1).toLowerCase());
for(let placeholder of placeholders) {
if(!field.placeholders[placeholder]) {
console.error(`❌ Missing placeholder "${placeholder}" on "${fieldName}" in _locales/${localeName}/messages.json`);
errors = true;
}
if(!field.placeholders[placeholder].content) {
console.error(`❌ Missing placeholder content "${placeholder}" on "${fieldName}" in _locales/${localeName}/messages.json`);
errors = true;
}
}
}
}
}
}
if(errors) {
process.exit(1);
} else {
console.log('\n✅ All locale files are valid.');
}