forked from chriskjou/langplusplus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
209 lines (181 loc) · 7.48 KB
/
index.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
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
<!DOCTYPE html>
<html lang="en">
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.2/ace.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.2/ext-language_tools.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.2/mode-snippets.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.2/ext-modelist.js"></script>
<script src="https://d3js.org/d3.v5.min.js"></script>
<script src="https://d3js.org/d3.v5.js"></script>
<link rel="stylesheet" type="text/css" href="css/main.css">
<link rel='icon' type='image/x-icon' href='./assets/logo/favicon_ouline.ico'>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script> //parsing the translations
var staticWordCompleter;
var language;
var prog_lang;
function parseCSV(){ // parsing csv before add completer
language = document.getElementById("language").value;
prog_lang = document.getElementById("prog_lang").value;
var file_name = "translations/" + language + "_" + prog_lang + ".csv";;
return d3.csv(file_name);
}
function update_translations() {
parsed = arguments[0];
// ensure naming convention of cpp mode for editor
if (prog_lang == "c_cpp"){
prog_lang = "cpp";
}
var dict = {};
for (var i = 0; i < parsed.length; i++) {
dict[parsed[i][language]] = parsed[i][prog_lang];
}
//add custom completer w/ translations
var wordList = [];
for (var i = 0; i < parsed.length; i++) {
wordList.push(parsed[i][language]);
}
staticWordCompleter = {
getCompletions: function(editor, session, pos, prefix, callback) {
callback(null, wordList.map(function(word) {
return {
caption: word,
value: dict[word],
meta: dict[word]
};
}));
}
}
langTools.addCompleter(staticWordCompleter);
}
</script>
<head>
<meta charset="UTF-8">
<title>lang++</title>
<div class="header">
<h1>
<img src="./assets/logo/logo.png" height="75">
<div class="switch">🌘</span>
</div>
</h1>
</div>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<div class="instructions">
To get started, type a word in the selected language.
</div>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<select id="language">
<option value="Chinese">Chinese</option>
<option value="Spanish">Spanish</option>
<option value="Russian">Russian</option>
<option value="Japanese">Japanese</option>
<option value="French">French</option>
<option value="German">German</option>
<option value="Italian">Italian</option>
<option value="Japanese">Japanese</option>
<option value="Persian">Persian</option>
<option value="Portuguese">Portuguese</option>
<option value="Spanish">Spanish</option>
</select>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<select id="prog_lang">
<option value="c_cpp">c_cpp</option>
<option value="java">java</option>
<option value="python">python</option>
<option value="swift">swift</option>
</select>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<p></p>
</head>
<body>
<div id="editor">
function foo() {
var x = "Welcome to lang++!";
}
</div>
<script>
var langTools = ace.require("ace/ext/language_tools");
var editor = ace.edit("editor");
var modelist = ace.require("ace/ext/modelist");
editor.getSession().setMode("ace/mode/c_cpp");
var theme = editor.setTheme("ace/theme/textmate");
editor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true
});
// wait for parseCSV to finish before adding completer
parseCSV().then(function(results){
update_translations(results);
});
</script>
<script>
//if lang/prog_lang selections change
$('select').on('change', function () {
let completers = editor.completers;
completers.splice(completers.indexOf(staticWordCompleter), 1);
var newMode = document.getElementById("prog_lang").value;
editor.getSession().setMode("ace/mode/" + newMode);
parseCSV().then(function(results){
update_translations(results);
});
});
// change based on language
$('#language').on('change', function(){
console.log($('#language').val());
$('#prog_lang').html('');
if ($('#language').val()=="Chinese"){
$('#prog_lang').append('<option value="c_cpp">c_cpp</option>');
$('#prog_lang').append('<option value="java">java</option>');
$('#prog_lang').append('<option value="swift">swift</option>');
}
else if ($('#language').val()=="Spanish"){
$('#prog_lang').append('<option value="c_cpp">c_cpp</option>');
$('#prog_lang').append('<option value="python">python</option>');
}
else if ($('#language').val()=="Russian"){
$('#prog_lang').append('<option value="python">python</option>');
}
else if ($('#language').val()=="Japanese"){
$('#prog_lang').append('<option value="c_cpp">c_cpp</option>');
}
else if ($('#language').val()=="French"){
$('#prog_lang').append('<option value="python">python</option>');
}
else if ($('#language').val()=="Portuguese"){
$('#prog_lang').append('<option value="c_cpp">c_cpp</option>');
$('#prog_lang').append('<option value="java">java</option>');
$('#prog_lang').append('<option value="python">python</option>');
}
else if ($('#language').val()=="Persian"){
$('#prog_lang').append('<option value="c_cpp">c_cpp</option>');
}
else if ($('#language').val()=="Italian"){
$('#prog_lang').append('<option value="c_cpp">c_cpp</option>');
}
else if ($('#language').val()=="German"){
$('#prog_lang').append('<option value="python">python</option>');
}
else {
// default language options
$('#prog_lang').append('<option value="c_cpp">c_cpp</option>');
}
});
</script>
<script>
$( ".switch" ).on("click", function() {
if( $( "body" ).hasClass( "dark" )) {
$( "body" ).removeClass( "dark" );
$( ".switch" ).text( "🌘" );
$theme = editor.setTheme("ace/theme/textmate");
} else {
$( "body" ).addClass( "dark" );
$( ".switch" ).text( "🌖" );
$theme = editor.setTheme("ace/theme/dracula");
}
});
</script>
</body>
<footer>
<a href="https://zh.cppreference.com/w/" target="_blank">reference</a>
</footer>
</html>