-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimplified-traditional-chinese-converter.html
51 lines (50 loc) · 2.74 KB
/
simplified-traditional-chinese-converter.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/data.min.js"></script> <!-- Required -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/data.cn2t.min.js"></script> <!-- For Simplified to Traditional -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/data.t2cn.min.js"></script> <!-- For Traditional Chinese to Simplified Chinese -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/bundle-browser.min.js"></script><!-- Required -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script>
<title>Simplified Traditional Chinese Converter</title>
</head>
<body>
<div align="center"> <input type="file" id="input-file" onchange="loadFile(event)" accept=".txt"> <button onclick="convertToSimple()">Convert to Simplified</button> <button onclick="convertToTraditional()">Convert to Traditional</button> </div>
<script>
let fileContent = null;
const converterToTraditional = OpenCC.Converter({ from: 'cn', to: 'tw' });
const converterToSimplified = OpenCC.Converter({ from: 'tw', to: 'cn' });
function loadFile(event) {
const input = event.target;
const reader = new FileReader();
reader.onload = function(){
fileContent = reader.result;
};
reader.readAsText(input.files[0]);
};
function convertToTraditional() {
if (fileContent) {
let translated = converterToTraditional(fileContent);
const input = document.getElementById('input-file');
const filename = input.files[0].name.split('.').slice(0, -1).join('.') + "_trad.txt";
const blob = new Blob([translated], {type: "text/plain;charset=utf-8"});
saveAs(blob, filename);
}
}
function convertToSimple() {
if (fileContent) {
let translated = converterToSimplified(fileContent);
const input = document.getElementById('input-file');
const filename = input.files[0].name.split('.').slice(0, -1).join('.') + "_sim.txt";
const blob = new Blob([translated], {type: "text/plain;charset=utf-8"});
saveAs(blob, filename);
}
}
</script>
</body>
</html>