-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtransliteration-lite.js
More file actions
38 lines (34 loc) · 2.89 KB
/
Copy pathtransliteration-lite.js
File metadata and controls
38 lines (34 loc) · 2.89 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
(function () {
const mapping = {
// Cyrillic (Serbian, Russian, etc.)
'\u0410': 'A', '\u0411': 'B', '\u0412': 'V', '\u0413': 'G', '\u0414': 'D', '\u0402': 'Đ', '\u0415': 'E', '\u0401': 'Yo', '\u0416': 'Ž', '\u0417': 'Z',
'\u0418': 'I', '\u0419': 'Y', '\u0408': 'J', '\u041a': 'K', '\u041b': 'L', '\u0409': 'Lj', '\u041c': 'M', '\u041d': 'N', '\u040a': 'Nj', '\u041e': 'O',
'\u041f': 'P', '\u0420': 'R', '\u0421': 'S', '\u0422': 'T', '\u040b': 'Ć', '\u0423': 'U', '\u0424': 'F', '\u0425': 'H', '\u0426': 'C', '\u0427': 'Č',
'\u040f': 'Dž', '\u0428': 'Š', '\u0429': 'Shch', '\u042a': '', '\u042b': 'Y', '\u042c': '', '\u042d': 'E', '\u042e': 'Yu', '\u042f': 'Ya',
'\u0430': 'a', '\u0431': 'b', '\u0432': 'v', '\u0433': 'g', '\u0434': 'd', '\u0452': 'đ', '\u0435': 'e', '\u0451': 'yo', '\u0436': 'ž', '\u0437': 'z',
'\u0438': 'i', '\u0439': 'y', '\u0458': 'j', '\u043a': 'k', '\u043b': 'l', '\u0459': 'lj', '\u043c': 'm', '\u043d': 'n', '\u045a': 'nj', '\u043e': 'o',
'\u043f': 'p', '\u0440': 'r', '\u0441': 's', '\u0442': 't', '\u045b': 'ć', '\u0443': 'u', '\u0444': 'f', '\u0445': 'h', '\u0446': 'c', '\u0447': 'č',
'\u045f': 'dž', '\u0448': 'š', '\u0449': 'shch', '\u044a': '', '\u044b': 'y', '\u044c': '', '\u044d': 'e', '\u044e': 'yu', '\u044f': 'ya',
// Greek
'\u0391': 'A', '\u0392': 'V', '\u0393': 'G', '\u0394': 'D', '\u0395': 'E', '\u0396': 'Z', '\u0397': 'I', '\u0398': 'Th', '\u0399': 'I', '\u039a': 'K', '\u039b': 'L', '\u039c': 'M', '\u039d': 'N', '\u039e': 'X', '\u039f': 'O', '\u03a0': 'P', '\u03a1': 'R', '\u03a3': 'S', '\u03a4': 'T', '\u03a5': 'Y', '\u03a6': 'F', '\u03a7': 'Ch', '\u03a8': 'Ps', '\u03a9': 'O',
'\u03b1': 'a', '\u03b2': 'v', '\u03b3': 'g', '\u03b4': 'd', '\u03b5': 'e', '\u03b6': 'z', '\u03b7': 'i', '\u03b8': 'th', '\u03b9': 'i', '\u03ba': 'k', '\u03bb': 'l', '\u03bc': 'm', '\u03bd': 'n', '\u03be': 'x', '\u03bf': 'o', '\u03c0': 'p', '\u03c1': 'r', '\u03c3': 's', '\u03c4': 't', '\u03c5': 'y', '\u03c6': 'f', '\u03c7': 'ch', '\u03c8': 'ps', '\u03c9': 'o', '\u03c2': 's',
// Accented Greek
'\u0386': 'A', '\u0388': 'E', '\u0389': 'I', '\u038a': 'I', '\u038c': 'O', '\u038e': 'Y', '\u038f': 'O',
'\u03ac': 'a', '\u03ad': 'e', '\u03ae': 'i', '\u03af': 'i', '\u03cc': 'o', '\u03cd': 'y', '\u03ce': 'o', '\u03ca': 'i', '\u03cb': 'y', '\u0390': 'i', '\u03b0': 'y'
};
// Correctly handle digraphs when searching
const digraphs = {
'\u0409': 'Lj', '\u040a': 'Nj', '\u040f': 'Dž',
'\u0459': 'lj', '\u045a': 'nj', '\u045f': 'dž'
};
window.transliterate = function (text) {
if (!text) return text;
let result = '';
for (let i = 0; i < text.length; i++) {
const char = text[i];
const mapped = mapping[char];
result += (mapped !== undefined) ? mapped : char;
}
return result;
};
})();