-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_rules.js
97 lines (50 loc) · 1.78 KB
/
check_rules.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
const ph1 = `{\S*?}`;
const ph2 = `%[0-9a-z]`;
function checkTranslation(s, t) {
const errMsgs = [], warnMsgs = [];
let a, b;
// Test 1
a = [...s.matchAll(ph1)].sort().toString();
if (a) {
b = [...t.matchAll(ph1)].sort().toString();
if (new Set(a.split(',')).difference(new Set(b.split(','))).size) {
errMsgs.push('There are missing placeholder(s): {}');
}
else if (a != b) {
warnMsgs.push("The number of placeholders doesn't match: {}");
}
}
// Test 2
a = [...s.matchAll(ph2)].sort().toString();
if (a) {
b = [...t.matchAll(ph2)].sort().toString();
if (new Set(a.split(',')).difference(new Set(b.split(','))).size) {
errMsgs.push('There are missing placeholder(s): %');
}
else if (a != b) {
warnMsgs.push("The number of placeholders doesn't match: %");
}
}
if (t.trim() == '' && s.trim() != '') {
warnMsgs.push('Translation is empty.');
}
if (s.slice(-3) == '...') {
if (t.slice(-3) != '...' && t.slice(-1) != '…') {
warnMsgs.push('There are missing three dots (...) at the end.');
}
}
return [errMsgs, warnMsgs];
}
function checkTranslation_ja(s, t) {
const [errMsgs, warnMsgs] = checkTranslation(s, t);
if (s.slice(-1) == '…' && t.slice(-3) != '...') {
warnMsgs.push('There are missing 3 dots at the end (must be 3 dots).');
}
if (t.indexOf('…') != -1) {
warnMsgs.push('There is an ellipsis character (…).');
}
if (s.indexOf('....') == -1 && s.indexOf('……') == -1 && t.indexOf('....') != -1) {
warnMsgs.push('There is unexpected four dots (....).');
}
return [errMsgs, warnMsgs];
}