-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLanguage.js
More file actions
58 lines (48 loc) · 1.37 KB
/
Copy pathLanguage.js
File metadata and controls
58 lines (48 loc) · 1.37 KB
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
/*
Functions for handling language
*/
"use strict";
class Language {
constructor() {
}
static isJapaneseQuoted(s) {
return s.includes("「");
}
static stripJapaneseQuotes(s) {
return s.replace(/「|」/g, "");
}
static isHiragana(c) {
let code = c.charCodeAt(0);
return (0x303f < code) && (code <= 0x309f);
}
static isKatakana(c) {
let code = c.charCodeAt(0);
return (0x309f < code) && (code <= 0x30ff);
}
static hasSuttering(s) {
// Stuttering doesn't only occur in spoken text
let temp = Language.stripJapaneseQuotes(s).trim();
for(let i = 0; i < s.length - 2; ++i) {
if (Language.isPosibleStutter(temp.substring(i, i + 3))) {
return true;
}
}
return false;
}
static isPosibleStutter(s) {
// stuttering looks like "<char>、<char>"
return (s[1] === '、')
&& (s[0] === s[2])
&& (Language.isHiragana(s[0]) || Language.isKatakana(s[0]));
}
static notesForMyTranslation(originalJapanese) {
let notes = "";
if (Language.hasSuttering(originalJapanese)) {
notes += "(possible stuttering) "
}
if (Language.isJapaneseQuoted(originalJapanese)) {
notes += "「」";
}
return notes;
}
}