Commit 46f91efa authored by Tommy Chan's avatar Tommy Chan

languages and stuff

parent 77476daf
......@@ -34,7 +34,7 @@ body::after {
bottom: 0;
right: 0;
position: absolute;
z-index: -1;
z-index: -1;
}
#title {
......@@ -83,4 +83,7 @@ body::after {
#fontsize_selector,
#theme_selector {
width:100px;
}
\ No newline at end of file
}
#storynum {
width:100px;
}
......@@ -39,7 +39,7 @@
title="Ctrl + S - Save File; Ctrl + F - Find; Ctrl+H - Find & Replace; ...">[?]</a>
<div id="fileDiv">
<label for="fileInput">Open .xml file:</label>
<label for="fileInput" id="xmlopen">Open .xml file:</label>
<br>
<input id="fileInput" type="file">
</div>
......@@ -54,7 +54,7 @@
<span id="fontsize" class="css3-selectbox">
<select id="fontsize_selector">
<option value="">---Font size---</option>
<option value="" id="fontsize_text">---Font size---</option>
<option value="10px">10px</option>
<option value="12px">12px</option>
<option value="14px" selected>14px</option>
......@@ -71,7 +71,7 @@
<span id="theme" class="css3-selectbox">
<select id="theme_selector">
<option value="">---Theme---</option>
<option value="" id="theme_text">---Theme---</option>
<option value="ambiance">ambiance</option>
<option value="chaos">chaos</option>
<option value="chrome" selected>chrome</option>
......@@ -124,8 +124,22 @@
<input type="submit" value="Save as..." id="save_as" />
<input type="submit" value="Generate EXE" id="generate_exe"><br/>
Replace story(1-7): <input type="number" id="storynum" value="1" /><br/>
Story name: <input type="text" id="storyname" />
<span id="replace_story_text">Replace story:</span>
<span class="css3-selectbox">
<select id="storynum">
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select>
</span>
<br/>
<span id="storyname_eng_text">Story name(English): </span><input type="text" id="storyname" />
<input type="submit" id="engtochi_text" value="Eng to Chi" onclick="engtochi()"/>
<span id="storyname_chi_text">Story name(Chinese): </span><input type="text" id="storynameb5" />
</div>
</body>
......
......@@ -58,9 +58,9 @@ class Editor {
setLines() {
let lines = this.editor.session.getLength();
let linecol = this.editor.selection.getCursor();
$('#lines').html(`<strong>Ln:<\/strong> ${linecol.row+1}
<strong>Ch:<\/strong>${linecol.column} |
<strong>Total Ln:<\/strong> ${lines}`);
$('#lines').html(`<strong id="editor_ln">Ln:<\/strong> ${linecol.row+1}
<strong id="editor_ch">Ch:<\/strong>${linecol.column} |
<strong id="editor_ttln">Total Ln:<\/strong> ${lines}`);
}
changeTheme(theme) {
......
......@@ -40,6 +40,9 @@ class File {
fileName = prompt("Please enter the file name", fileName); // FIXME Doesn't work in nodejs
if (!fileName) return;
let blob = new Blob([data], {
......
const glob = require( 'glob' );
const path = require( 'path' );
const $ = require('jquery');
class Languages {
constructor() {
this.lang = [];
}
loadLanguages() {
if (this.lang.length === 0) {
const that = this;
glob.sync( './languages/*.json' ).forEach( function( file ) {
that.lang.push( require(path.resolve( file )) );
});
}
}
get languages() {
if (this.lang.length === 0) {
return undefined;
}
return this.lang;
}
setLanguage(l) {
for (let i = 0, len = this.lang.length; i < len; i++) {
if (this.lang[i].language === l) {
break;
}
}
if (i = this.lang.length) return;
let lang = this.lang[i];
$("title").text(lang.title);
$("#title").text(lang.title);
$("#save_as").text(lang.save_as);
$("#generate_exe").text(lang.generate_exe);
$("#replace_story_text").text(lang.replace_story);
$("#xmlopen").text(lang.open_xml);
$("#fontsize_text").text(lang.fontsize);
$("#theme_text").text(lang.theme);
$("#storyname_eng_text").text(lang.storyname_eng);
$("#storyname_chi_text").text(lang.storyname_chi);
$("#engtochi_text").text(lang.engtochi);
$("#editor_ln").text(lang.editor_line);
$("#editor_ch").text(lang.editor_ch);
$("#editor_ttln").text(lang.editor_totalline);
$("#").text(lang.error);
$("#").text(lang.api_error);
$("#").text(lang.empty_textarea_error);
$("#").text(lang.enter_filename_error);
$("#").text(lang.saved);
$("#").text(lang.xml_only_error);
$("#").text(lang.editor_size_lastm);
$("#").text(lang.replace_story_error);
$("#").text(lang.story_engname_error);
$("#").text(lang.story_chiname_error);
$("#").text(lang.empty_story_error);
$("#").text(lang.exists_error);
$("#").text(lang.large_size_error);
$("#").text(lang.save_error);
$("#").text(lang.savename_error);
}
}
module.exports = Languages;
......@@ -4,12 +4,25 @@
const {
spawn
} = require('child_process');
const translate = require('google-translate-api');
let target_dir = 'uploads/';
function engtochi() {
let eng = document.getElementById("storyname");
let chi = document.getElementById("storynameb5");
translate(eng.value, {from: 'en', to: 'zh-TW'}).then(res => {
chi.value = res.text;
}).catch(err => {
console.error(err);
});
}
function generateExe() {
if (!fs.existsSync(target_dir)){
fs.mkdirSync(target_dir);
}
......@@ -30,6 +43,7 @@ function generateExe() {
let target_filename = d;
let target_filename_story_list = `${d}storylist.xml`;
let story_name = $("#storyname").val();
let story_nameb5 = $("#storynameb5").val();
let story_list = {
1:"First Match",
2:"Trap",
......@@ -42,22 +56,35 @@ function generateExe() {
9:"Betrayal",
10:"Death Match"
};
let story_listb5 = {
1:"初戰",
2:"陷阱",
3:"潰敗",
4:"潛入",
5:"逃獄",
6:"醒覺",
7:"約定",
8:"特訓",
9:"背叛",
10:"死戰"
};
let story_number = $("#storynum").val();
story_list[story_number] = story_name;
story_listb5[story_number] = story_nameb5;
let storylistdata=`<storylist>
<story><storyid>story01</storyid><bgid>story01</bgid><storyname><en>1. ${story_list[1]}</en><b5>第一話 初戰</b5></storyname></story>
<story><storyid>story02</storyid><bgid>story02b</bgid><storyname><en>2. ${story_list[2]}</en><b5>第二話 陷阱</b5></storyname></story>
<story><storyid>story03</storyid><bgid>story03a</bgid><storyname><en>3. ${story_list[3]}</en><b5>第三話 潰敗</b5></storyname></story>
<story><storyid>story04</storyid><bgid>story04a</bgid><storyname><en>4. ${story_list[4]}</en><b5>第四話 潛入</b5></storyname></story>
<story><storyid>story05</storyid><bgid>prison2</bgid><storyname><en>5. ${story_list[5]}</en><b5>第五話 逃獄</b5></storyname></story>
<story><storyid>story06</storyid><bgid>story06c</bgid><storyname><en>6. ${story_list[6]}</en><b5>第六話 醒覺</b5></storyname></story>
<story><storyid>story07</storyid><bgid>desert</bgid><storyname><en>7. ${story_list[7]}</en><b5>第七話 約定</b5></storyname></story>
<story><storyid>story08</storyid><bgid>hill_grass</bgid><storyname><en>8. ${story_list[8]}</en><b5>第八話 特訓</b5></storyname></story>
<story><storyid>story09</storyid><bgid>forest_grass</bgid><storyname><en>9. ${story_list[9]}</en><b5>第九話 背叛</b5></storyname></story>
<story><storyid>story10</storyid><bgid>room1</bgid><storyname><en>10. ${story_list[10]}</en><b5>第十話 死戰</b5></storyname></story>
<story><storyid>story01</storyid><bgid>story01</bgid><storyname><en>1. ${story_list[1]}</en><b5>第一話 ${story_listb5[1]}</b5></storyname></story>
<story><storyid>story02</storyid><bgid>story02b</bgid><storyname><en>2. ${story_list[2]}</en><b5>第二話 ${story_listb5[2]}</b5></storyname></story>
<story><storyid>story03</storyid><bgid>story03a</bgid><storyname><en>3. ${story_list[3]}</en><b5>第三話 ${story_listb5[3]}</b5></storyname></story>
<story><storyid>story04</storyid><bgid>story04a</bgid><storyname><en>4. ${story_list[4]}</en><b5>第四話 ${story_listb5[4]}</b5></storyname></story>
<story><storyid>story05</storyid><bgid>prison2</bgid><storyname><en>5. ${story_list[5]}</en><b5>第五話 ${story_listb5[5]}</b5></storyname></story>
<story><storyid>story06</storyid><bgid>story06c</bgid><storyname><en>6. ${story_list[6]}</en><b5>第六話 ${story_listb5[6]}</b5></storyname></story>
<story><storyid>story07</storyid><bgid>desert</bgid><storyname><en>7. ${story_list[7]}</en><b5>第七話 ${story_listb5[7]}</b5></storyname></story>
<story><storyid>story08</storyid><bgid>hill_grass</bgid><storyname><en>8. ${story_list[8]}</en><b5>第八話 ${story_listb5[8]}</b5></storyname></story>
<story><storyid>story09</storyid><bgid>forest_grass</bgid><storyname><en>9. ${story_list[9]}</en><b5>第九話 ${story_listb5[9]}</b5></storyname></story>
<story><storyid>story10</storyid><bgid>room1</bgid><storyname><en>10. ${story_list[10]}</en><b5>第十話 ${story_listb5[10]}</b5></storyname></story>
</storylist>
`;
......@@ -69,8 +96,13 @@ function generateExe() {
}
if (story_name == "" || story_name == null) {
dialog.err("Please enter a name for your story.", 'Error');
return
dialog.err("Please enter a English name for your story.", 'Error');
return;
}
if (story_nameb5 == "" || story_nameb5 == null) {
dialog.err("Please enter a Chinese name for your story.", 'Error');
return;
}
const data = File.getDataFromEditor();
......@@ -138,22 +170,36 @@ function create_mod(filename) {
9:"Betrayal",
10:"Death Match"
}
let story_listb5 = {
1:"初戰",
2:"陷阱",
3:"潰敗",
4:"潛入",
5:"逃獄",
6:"醒覺",
7:"約定",
8:"特訓",
9:"背叛",
10:"死戰"
};
let story_number = document.getElementById("storynum").value;
let story_number = $("#storynum").val();
let story_name = document.getElementById("storyname").value;
let story_nameb5 = document.getElementById("storynameb5").value;
story_list[story_number] = story_name;
story_listb5[story_number] = story_nameb5;
let storynumber = story_ids[story_number];
let storylistdata=`<storylist>
<story><storyid>story01</storyid><bgid>story01</bgid><storyname><en>1. ${story_list[1]}</en><b5>第一話 初戰</b5></storyname></story>
<story><storyid>story02</storyid><bgid>story02b</bgid><storyname><en>2. ${story_list[2]}</en><b5>第二話 陷阱</b5></storyname></story>
<story><storyid>story03</storyid><bgid>story03a</bgid><storyname><en>3. ${story_list[3]}</en><b5>第三話 潰敗</b5></storyname></story>
<story><storyid>story04</storyid><bgid>story04a</bgid><storyname><en>4. ${story_list[4]}</en><b5>第四話 潛入</b5></storyname></story>
<story><storyid>story05</storyid><bgid>prison2</bgid><storyname><en>5. ${story_list[5]}</en><b5>第五話 逃獄</b5></storyname></story>
<story><storyid>story06</storyid><bgid>story06c</bgid><storyname><en>6. ${story_list[6]}</en><b5>第六話 醒覺</b5></storyname></story>
<story><storyid>story07</storyid><bgid>desert</bgid><storyname><en>7. ${story_list[7]}</en><b5>第七話 約定</b5></storyname></story>
<story><storyid>story08</storyid><bgid>hill_grass</bgid><storyname><en>8. ${story_list[8]}</en><b5>第八話 特訓</b5></storyname></story>
<story><storyid>story09</storyid><bgid>forest_grass</bgid><storyname><en>9. ${story_list[9]}</en><b5>第九話 背叛</b5></storyname></story>
<story><storyid>story10</storyid><bgid>room1</bgid><storyname><en>10. ${story_list[10]}</en><b5>第十話 死戰</b5></storyname></story>
<story><storyid>story01</storyid><bgid>story01</bgid><storyname><en>1. ${story_list[1]}</en><b5>第一話 ${story_listb5[1]}</b5></storyname></story>
<story><storyid>story02</storyid><bgid>story02b</bgid><storyname><en>2. ${story_list[2]}</en><b5>第二話 ${story_listb5[2]}</b5></storyname></story>
<story><storyid>story03</storyid><bgid>story03a</bgid><storyname><en>3. ${story_list[3]}</en><b5>第三話 ${story_listb5[3]}</b5></storyname></story>
<story><storyid>story04</storyid><bgid>story04a</bgid><storyname><en>4. ${story_list[4]}</en><b5>第四話 ${story_listb5[4]}</b5></storyname></story>
<story><storyid>story05</storyid><bgid>prison2</bgid><storyname><en>5. ${story_list[5]}</en><b5>第五話 ${story_listb5[5]}</b5></storyname></story>
<story><storyid>story06</storyid><bgid>story06c</bgid><storyname><en>6. ${story_list[6]}</en><b5>第六話 ${story_listb5[6]}</b5></storyname></story>
<story><storyid>story07</storyid><bgid>desert</bgid><storyname><en>7. ${story_list[7]}</en><b5>第七話 ${story_listb5[7]}</b5></storyname></story>
<story><storyid>story08</storyid><bgid>hill_grass</bgid><storyname><en>8. ${story_list[8]}</en><b5>第八話 ${story_listb5[8]}</b5></storyname></story>
<story><storyid>story09</storyid><bgid>forest_grass</bgid><storyname><en>9. ${story_list[9]}</en><b5>第九話 ${story_listb5[9]}</b5></storyname></story>
<story><storyid>story10</storyid><bgid>room1</bgid><storyname><en>10. ${story_list[10]}</en><b5>第十話 ${story_listb5[10]}</b5></storyname></story>
</storylist>
`;
......
......@@ -2,6 +2,9 @@
const $ = require('jquery');
const dialog = require('dialog');
const Languages = require('./js/Languages.js');
let lang;
$(document).ready(function () {
......@@ -25,4 +28,9 @@ $(document).ready(function () {
generateExe();
}
});
// Languages
lang = new Languages();
lang.loadLanguages();
console.log(lang.languages[0].language);
});
{
"language" : "中文",
"title": "HF - 線上修改故事",
"save_as": "另存新檔",
"generate_exe": "建立EXE檔",
"replace_story": "取代故事:",
"open_xml":"開啓 .xml 檔案:",
"fontsize":"---字體---",
"theme":"---主題---",
"storyname_eng":"故事名稱(英文):",
"storyname_chi":"故事名稱(中文):",
"engtochi":"英文轉換中文",
"editor_line":"行:",
"editor_ch":"字元:",
"editor_totalline":"總共行數:",
"error":"錯誤",
"api_error":"此瀏覽器不支援所需的APIs.",
"empty_textarea_error":"内容不能爲空白。",
"enter_filename_error":"請輸入檔案名稱",
"saved":"儲存成功!",
"xml_only_error":"只能開啓 XML 檔案。",
"editor_size_lastm":" 位元,最後修改: ",
"replace_story_error":"只能夠替換故事 1-7.",
"story_engname_error":"請爲你的故事填上英文名稱。",
"story_chiname_error":"請爲你的故事填上中文名稱。",
"empty_story_error":"故事不能爲空白。",
"exists_error":"抱歉,此檔案已經存在。",
"large_size_error":"抱歉,你的檔案太大。",
"save_error":"抱歉,儲存故事時發生錯誤。",
"savename_error":"抱歉,儲存故事名稱時發生錯誤。"
}
{
"language" : "English",
"title": "HF - Online Story Editor",
"save_as": "Save as...",
"generate_exe": "Generate EXE",
"replace_story": "Replace story:",
"open_xml":"Open .xml file:",
"fontsize":"---Font size---",
"theme":"---Theme---",
"storyname_eng":"Story name(English):",
"storyname_chi":"Story name(Chinese):",
"engtochi":"Eng to Chi",
"editor_line":"Ln:",
"editor_ch":"Ch:",
"editor_totalline":"Total Ln:",
"error":"Error",
"api_error":"The File APIs are not fully supported in this browser.",
"empty_textarea_error":"Text area is empty.",
"enter_filename_error":"Please enter the file name",
"saved":"The file was saved!",
"xml_only_error":"XML file only.",
"editor_size_lastm":" bytes, last modified: ",
"replace_story_error":"Sorry, you can only replace story 1-7.",
"story_engname_error":"Please enter a English name for your story.",
"story_chiname_error":"Please enter a Chinese name for your story.",
"empty_story_error":"Story cannot be empty.",
"exists_error":"Sorry, the story file already exists.",
"large_size_error":"Sorry, your story is too large.",
"save_error":"Sorry, there was an error saving your story.",
"savename_error":"Sorry, there was an error saving the story name."
}
This diff is collapsed.
......@@ -27,6 +27,10 @@
"jquery": "^3.3.1"
},
"dependencies": {
"dialog": "^0.3.1"
"dialog": "^0.3.1",
"electron-prompt": "^1.1.0-1",
"glob": "^7.1.2",
"google-translate-api": "^2.3.0",
"smalltalk": "^3.1.1"
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment