Last active
March 19, 2016 13:48
-
-
Save Lunatrius/a72dab3aa3c9be615924 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.nofile { | |
color: red; | |
} | |
.nofile.highlighted { | |
color: #ff9999 !important; | |
} | |
.file { | |
color: orange; | |
} | |
.file.highlighted { | |
color: #ffdb99 !important; | |
} | |
.warning { | |
font-weight: bold; | |
color: red; | |
border: 1px solid red; | |
background-color: #ffcccc; | |
padding: 5pt; | |
} | |
.notice { | |
font-weight: bold; | |
color: #3f3fff; | |
border: 1px solid #3f3fff; | |
background-color: #d8d8ff; | |
padding: 5pt; | |
} | |
.comment { | |
font-weight: bold; | |
} | |
.hide { | |
display: none; | |
} | |
.pre { | |
white-space: pre; | |
background-color: #dddddd; | |
} | |
body { | |
font-size: 11pt; | |
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; | |
} | |
table { | |
width: 100%; | |
} | |
table#input input[type="text"], | |
table#input table#input textarea { | |
width: 95%; | |
} | |
table#input textarea { | |
height: 5em; | |
} | |
table#table textarea { | |
width: 100%; | |
height: 1.0em; | |
border: 1px solid #bfbfbf; | |
word-wrap: break-word; | |
} | |
table#table textarea:invalid { | |
background-color: #fee7e7; | |
} | |
table#table textarea:valid { | |
background-color: #eefee7; | |
} | |
table#table tr td { | |
border-bottom: 1px solid #dddddd; | |
word-wrap: break-word; | |
} | |
table#table th { | |
width: 50%; | |
} | |
table tr td:first-child { | |
width: 150px; | |
} | |
textarea { | |
width: 100%; | |
font-size: 1em; | |
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; | |
resize: vertical; | |
} | |
textarea#output { | |
background-color: #eeeeee; | |
} | |
textarea#input, | |
textarea#output { | |
height: 15em; | |
} | |
div.ui-tooltip { | |
font-size: 1em; | |
max-width: 50%; | |
} | |
.color-0 { | |
color: black; | |
} | |
.color-1 { | |
color: #0400aa; | |
} | |
.color-2 { | |
color: #02aa01; | |
} | |
.color-3 { | |
color: #05aaaa; | |
} | |
.color-4 { | |
color: #aa0000; | |
} | |
.color-5 { | |
color: #aa00aa; | |
} | |
.color-6 { | |
color: #ffaa02; | |
} | |
.color-7 { | |
color: #aaaaaa; | |
} | |
.color-8 { | |
color: #555555; | |
} | |
.color-9 { | |
color: #5654ff; | |
} | |
.color-a { | |
color: #56ff55; | |
} | |
.color-b { | |
color: #57ffff; | |
} | |
.color-c { | |
color: #ff5555; | |
} | |
.color-d { | |
color: #ff55ff; | |
} | |
.color-e { | |
color: #ffff56; | |
background-color: black; | |
} | |
.color-f { | |
color: white; | |
background-color: black; | |
} | |
@-webkit-keyframes obfuscated { | |
0% { | |
opacity: 0; | |
} | |
50% { | |
opacity: 1; | |
} | |
100% { | |
opacity: 0; | |
} | |
} | |
@-moz-keyframes obfuscated { | |
0% { | |
opacity: 0; | |
} | |
50% { | |
opacity: 1; | |
} | |
100% { | |
opacity: 0; | |
} | |
} | |
@-o-keyframes obfuscated { | |
0% { | |
opacity: 0; | |
} | |
50% { | |
opacity: 1; | |
} | |
100% { | |
opacity: 0; | |
} | |
} | |
@keyframes obfuscated { | |
0% { | |
opacity: 0; | |
} | |
50% { | |
opacity: 1; | |
} | |
100% { | |
opacity: 0; | |
} | |
} | |
obf { | |
-webkit-animation: obfuscated 0.5s infinite; | |
-moz-animation: obfuscated 0.5s infinite; | |
-o-animation: obfuscated 0.5s infinite; | |
animation: obfuscated 0.5s infinite; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<!-- | |
Yo. The code is shit. Close the source view. kthxbye | |
Still here? Fine. Just grab the files from: | |
* https://gist.github.com/a72dab3aa3c9be615924 | |
It's everything you need. | |
--> | |
<title>Translation Tool</title> | |
<meta charset="UTF-8" /> | |
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" /> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> | |
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script> | |
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/chosen/1.1.0/chosen.css" /> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/chosen/1.1.0/chosen.jquery.min.js"></script> | |
<link rel="stylesheet" href="translate.css" /> | |
</head> | |
<body> | |
<div> | |
<p class="warning hide" id="warning-popup"></p> | |
<a href="#" style="font-weight:bold;cursor:pointer;" onclick="$('#help').toggleClass('hide');return false;">Help</a> | |
<a href="#" style="font-weight:bold;cursor:pointer;" onclick="$('#guidelines').toggleClass('hide');return false;">Guidelines</a> | |
<div class="hide" id="help"> | |
<h3>Help</h3> | |
<ol id="help"> | |
<li>Fill in the link or paste the contents of the source and/or target language.</li> | |
<li>Click 'Load'.</li> | |
<li>Translate stuff.</li> | |
<li>Click 'Generate' and submit the translated file contents to the modder.</li> | |
<li>Try the examples: <span id="examples"></span></li> | |
</ol> | |
</div> | |
<div class="hide" id="guidelines"> | |
<h3>Guidelines</h3> | |
<ul id="guidelines"> | |
<li>Mod names should be left untranslated.</li> | |
<li><b>[LONG_WORD_FORCED_BREAK]</b> will be added to words longer than 75 characters.</li> | |
</ul> | |
</div> | |
<div id="github-list" class="hide"> | |
<table> | |
<tr> | |
<td>GitHub <a id="github-list-link">Linked Repository</a></td> | |
<td> | |
<select id="github-list-select"> | |
<option value=""></option> | |
</select> | |
</td> | |
</tr> | |
</table> | |
</div> | |
<table id="github"> | |
<tr> | |
<td>GitHub</td> | |
<td> | |
<input type="text" id="github-repo" size="150" placeholder="https://github.com/Lunatrius/InGame-Info-XML" /> | |
</td> | |
</tr> | |
<tr> | |
<td>Existing Localizations</td> | |
<td> | |
<select id="github-files"> | |
<optgroup label="Source(s)" id="github-files-src" disabled="disabled"></optgroup> | |
<optgroup label="Target(s)" id="github-files-dst"></optgroup> | |
</select> | |
</td> | |
</tr> | |
</table> | |
<input type="button" id="github-load" value="Load Existing Files" /> | |
<hr /> | |
<table id="input"> | |
<tr id="permalink-container" class="hide"> | |
<td>Permalink</td> | |
<td> | |
<input type="text" id="permalink" size="150" onclick="this.select()" readonly="readonly" /> | |
</td> | |
</tr> | |
<tr> | |
<td>Source</td> | |
<td> | |
<input type="radio" name="src-type" id="src-url-type" value="url" checked="checked" /> <input type="text" id="src-url" size="150" placeholder="https://somewebsite.com/path/to/your/file/en_US.lang" /> | |
<br /> | |
<input type="radio" name="src-type" id="src-text-type" value="text" /> <textarea type="text" id="src-text" size="150" placeholder="Paste the source language file here." style="width: 95%"></textarea> | |
</td> | |
</tr> | |
<tr> | |
<td>Target</td> | |
<td> | |
<input type="radio" name="dst-type" id="dst-url-type" value="url" checked="checked" /> <input type="text" id="dst-url" size="150" placeholder="https://somewebsite.com/path/to/your/file/de_DE.lang (optional)" /> | |
<br /> | |
<input type="radio" name="dst-type" id="dst-text-type" value="text" /> <textarea type="text" id="dst-text" size="150" placeholder="Paste the target language file here (optional)." style="width: 95%"></textarea> | |
</td> | |
</tr> | |
</table> | |
<input type="button" id="load" value="Load" /> | |
<input type="button" id="reset" value="Reset" /> | |
<br /> | |
<input type="button" id="loadlast" value="Load Autosave" disabled="disabled" /> | |
<input type="button" id="generate" value="Generate" disabled="disabled" /> | |
<input type="checkbox" id="ignore-same" name="ignore-same" /> <label for="ignore-same">Ignore same strings (source: mod.something=Test | target: mod.something=Test)</label> | |
</div> | |
<div id="output-container" class="hide"> | |
<textarea id="output" readonly="readonly"></textarea> | |
<br /> | |
<select id="lang" > | |
<option value="af_ZA">Afrikaans (af_ZA)</option> | |
<option value="ar_SA">العربية (ar_SA)</option> | |
<option value="bg_BG">Български (bg_BG)</option> | |
<option value="ca_ES">Català (ca_ES)</option> | |
<option value="cs_CZ">Čeština (cs_CZ)</option> | |
<option value="cy_GB">Cymraeg (cy_GB)</option> | |
<option value="da_DK">Dansk (da_DK)</option> | |
<option value="de_DE">Deutsch (de_DE)</option> | |
<option value="el_GR">Ελληνικά (el_GR)</option> | |
<option value="en_AU">Australian English (en_AU)</option> | |
<option value="en_CA">Canadian English (en_CA)</option> | |
<option value="en_GB">English (en_GB)</option> | |
<option value="en_PT">Pirate Speak (en_PT)</option> | |
<option value="eo_UY">Esperanto (eo_UY)</option> | |
<option value="es_AR">Español (es_AR)</option> | |
<option value="es_ES">Español (es_ES)</option> | |
<option value="es_MX">Español (es_MX)</option> | |
<option value="es_UY">Español (es_UY)</option> | |
<option value="es_VE">Español (es_VE)</option> | |
<option value="et_EE">Eesti (et_EE)</option> | |
<option value="eu_ES">Euskara (eu_ES)</option> | |
<option value="fi_FI">suomi (fi_FI)</option> | |
<option value="fr_CA">Français (fr_CA)</option> | |
<option value="fr_FR">Français (fr_FR)</option> | |
<option value="ga_IE">Gaeilge (ga_IE)</option> | |
<option value="gl_ES">Galego (gl_ES)</option> | |
<option value="he_IL">אנגלית (he_IL)</option> | |
<option value="hi_IN">अंग्रेज़ी (hi_IN)</option> | |
<option value="hr_HR">Hrvatski (hr_HR)</option> | |
<option value="hu_HU">Magyar (hu_HU)</option> | |
<option value="id_ID">Bahasa Indonesia (id_ID)</option> | |
<option value="is_IS">Íslenska (is_IS)</option> | |
<option value="it_IT">Italiano (it_IT)</option> | |
<option value="ja_JP">日本語 (ja_JP)</option> | |
<option value="ka_GE">ქართული (ka_GE)</option> | |
<option value="ko_KR">한국어 (ko_KR)</option> | |
<option value="kw_GB">Kernowek (kw_GB)</option> | |
<option value="lt_LT">Lietuvių (lt_LT)</option> | |
<option value="lv_LV">Latviešu (lv_LV)</option> | |
<option value="ms_MY">Bahasa Melayu (ms_MY)</option> | |
<option value="mt_MT">Malti (mt_MT)</option> | |
<option value="nl_NL">Nederlands (nl_NL)</option> | |
<option value="nn_NO">Norsk nynorsk (nn_NO)</option> | |
<option value="no_NO">Norsk (no_NO)</option> | |
<option value="pl_PL">Polski (pl_PL)</option> | |
<option value="pt_BR">Português (pt_BR)</option> | |
<option value="pt_PT">Português (pt_PT)</option> | |
<option value="qya_AA">Quenya (qya_AA)</option> | |
<option value="ro_RO">Română (ro_RO)</option> | |
<option value="ru_RU">Русский (ru_RU)</option> | |
<option value="sk_SK">Slovenčina (sk_SK)</option> | |
<option value="sl_SI">Slovenščina (sl_SI)</option> | |
<option value="sr_SP">Српски (sr_SP)</option> | |
<option value="sv_SE">Svenska (sv_SE)</option> | |
<option value="th_TH">ภาษาไทย (th_TH)</option> | |
<option value="tlh_AA">tlhIngan Hol (tlh_AA)</option> | |
<option value="tr_TR">Türkçe (tr_TR)</option> | |
<option value="uk_UA">Українська (uk_UA)</option> | |
<option value="vi_VN">Tiếng Việt (vi_VN)</option> | |
<option value="zh_CN">简体中文 (zh_CN)</option> | |
<option value="zh_TW">繁體中文 (zh_TW)</option> | |
</select> | |
<input type="button" id="save" value="Save" /> | |
</div> | |
<hr /> | |
<div id="container"></div> | |
<center>WTFPL © Lunatrius</center> | |
<script src="translate.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */ | |
var saveAs=saveAs||typeof navigator!=="undefined"&&navigator.msSaveOrOpenBlob&&navigator.msSaveOrOpenBlob.bind(navigator)||function(view){"use strict";if(typeof navigator!=="undefined"&&/MSIE [1-9]\./.test(navigator.userAgent)){return}var doc=view.document,get_URL=function(){return view.URL||view.webkitURL||view},save_link=doc.createElementNS("http://www.w3.org/1999/xhtml","a"),can_use_save_link="download"in save_link,click=function(node){var event=doc.createEvent("MouseEvents");event.initMouseEvent("click",true,false,view,0,0,0,0,0,false,false,false,false,0,null);node.dispatchEvent(event)},webkit_req_fs=view.webkitRequestFileSystem,req_fs=view.requestFileSystem||webkit_req_fs||view.mozRequestFileSystem,throw_outside=function(ex){(view.setImmediate||view.setTimeout)(function(){throw ex},0)},force_saveable_type="application/octet-stream",fs_min_size=0,arbitrary_revoke_timeout=500,revoke=function(file){var revoker=function(){if(typeof file==="string"){get_URL().revokeObjectURL(file)}else{file.remove()}};if(view.chrome){revoker()}else{setTimeout(revoker,arbitrary_revoke_timeout)}},dispatch=function(filesaver,event_types,event){event_types=[].concat(event_types);var i=event_types.length;while(i--){var listener=filesaver["on"+event_types[i]];if(typeof listener==="function"){try{listener.call(filesaver,event||filesaver)}catch(ex){throw_outside(ex)}}}},FileSaver=function(blob,name){var filesaver=this,type=blob.type,blob_changed=false,object_url,target_view,dispatch_all=function(){dispatch(filesaver,"writestart progress write writeend".split(" "))},fs_error=function(){if(blob_changed||!object_url){object_url=get_URL().createObjectURL(blob)}if(target_view){target_view.location.href=object_url}else{var new_tab=view.open(object_url,"_blank");if(new_tab==undefined&&typeof safari!=="undefined"){view.location.href=object_url}}filesaver.readyState=filesaver.DONE;dispatch_all();revoke(object_url)},abortable=function(func){return function(){if(filesaver.readyState!==filesaver.DONE){return func.apply(this,arguments)}}},create_if_not_found={create:true,exclusive:false},slice;filesaver.readyState=filesaver.INIT;if(!name){name="download"}if(can_use_save_link){object_url=get_URL().createObjectURL(blob);save_link.href=object_url;save_link.download=name;click(save_link);filesaver.readyState=filesaver.DONE;dispatch_all();revoke(object_url);return}if(view.chrome&&type&&type!==force_saveable_type){slice=blob.slice||blob.webkitSlice;blob=slice.call(blob,0,blob.size,force_saveable_type);blob_changed=true}if(webkit_req_fs&&name!=="download"){name+=".download"}if(type===force_saveable_type||webkit_req_fs){target_view=view}if(!req_fs){fs_error();return}fs_min_size+=blob.size;req_fs(view.TEMPORARY,fs_min_size,abortable(function(fs){fs.root.getDirectory("saved",create_if_not_found,abortable(function(dir){var save=function(){dir.getFile(name,create_if_not_found,abortable(function(file){file.createWriter(abortable(function(writer){writer.onwriteend=function(event){target_view.location.href=file.toURL();filesaver.readyState=filesaver.DONE;dispatch(filesaver,"writeend",event);revoke(file)};writer.onerror=function(){var error=writer.error;if(error.code!==error.ABORT_ERR){fs_error()}};"writestart progress write abort".split(" ").forEach(function(event){writer["on"+event]=filesaver["on"+event]});writer.write(blob);filesaver.abort=function(){writer.abort();filesaver.readyState=filesaver.DONE};filesaver.readyState=filesaver.WRITING}),fs_error)}),fs_error)};dir.getFile(name,{create:false},abortable(function(file){file.remove();save()}),abortable(function(ex){if(ex.code===ex.NOT_FOUND_ERR){save()}else{fs_error()}}))}),fs_error)}),fs_error)},FS_proto=FileSaver.prototype,saveAs=function(blob,name){return new FileSaver(blob,name)};FS_proto.abort=function(){var filesaver=this;filesaver.readyState=filesaver.DONE;dispatch(filesaver,"abort")};FS_proto.readyState=FS_proto.INIT=0;FS_proto.WRITING=1;FS_proto.DONE=2;FS_proto.error=FS_proto.onwritestart=FS_proto.onprogress=FS_proto.onwrite=FS_proto.onabort=FS_proto.onerror=FS_proto.onwriteend=null;return saveAs}(typeof self!=="undefined"&&self||typeof window!=="undefined"&&window||this.content);if(typeof module!=="undefined"&&module.exports){module.exports.saveAs=saveAs}else if(typeof define!=="undefined"&&define!==null&&define.amd!=null){define([],function(){return saveAs})} | |
/* @done */ | |
var TYPE_COMMENT = 1; | |
var TYPE_BLANK = 2; | |
var TYPE_ENTRY = 3; | |
var data = { | |
source: null, | |
target: null, | |
delay: 50, | |
srcType: null, | |
dstType: null | |
}; | |
var profiler = { | |
enabled: location.hostname === "dl.dropboxusercontent.com", | |
name: "", | |
last: 0, | |
time: function () { | |
return new Date().getTime(); | |
}, | |
start: function (name) { | |
if (!this.enabled) { | |
return; | |
} | |
this.name = name; | |
this.last = this.time(); | |
}, | |
endStart: function (name) { | |
if (!this.enabled) { | |
return; | |
} | |
var time = this.time(); | |
console.log(this.name + ": " + (time - this.last) + "ms"); | |
this.name = name; | |
this.last = time; | |
}, | |
end: function () { | |
if (!this.enabled) { | |
return; | |
} | |
var time = this.time(); | |
console.log(this.name + ": " + (time - this.last) + "ms"); | |
this.name = ""; | |
this.last = 0; | |
} | |
} | |
var translate = { | |
getText: function (url, callback) { | |
if (!url || url.length === 0) { | |
callback({ | |
"success": false, | |
"text": "" | |
}); | |
return; | |
} | |
var req = new XMLHttpRequest(); | |
req.open("GET", "https://cors-anywhere.herokuapp.com/" + url); | |
req.responseType = "text"; | |
req.onload = function (data) { | |
callback({ | |
"success": !/^(not found|\d+: \w+)\n?$/i.test(req.response), | |
"text": req.response | |
}); | |
}; | |
req.onerror = function (data) { | |
callback({ | |
"success": false, | |
"text": "" | |
}); | |
}; | |
req.send(); | |
}, | |
warning: function (message, prepend) { | |
$("<p></p>").addClass("warning").text("Warning: " + message)[prepend === true ? "prependTo" : "appendTo"]("#container"); | |
}, | |
notice: function (message, prepend) { | |
$("<p></p>").addClass("notice").text("Notice: " + message)[prepend === true ? "prependTo" : "appendTo"]("#container"); | |
}, | |
parse: function (text) { | |
var data = { | |
"mapping": {}, | |
"entries": [] | |
}; | |
text.split("\n").forEach(function (line, index) { | |
line = line.replace(/(^\s*|\s*$)/, ""); | |
if (line.indexOf("#") === 0 || line.indexOf("//") === 0) { | |
data.entries.push({ | |
"type": TYPE_COMMENT, | |
"value": line | |
}) | |
} else if (line.length === 0) { | |
data.entries.push({ | |
"type": TYPE_BLANK, | |
"value": "" | |
}) | |
} else { | |
var parts = line.split("="); | |
if (parts.length === 2) { | |
data.entries.push({ | |
"type": TYPE_ENTRY, | |
"value": parts[0] | |
}); | |
data.mapping[parts[0]] = parts[1]; | |
} | |
} | |
}) | |
return data; | |
}, | |
callbackFailed: function (message) { | |
$("#warning-popup") | |
.removeClass("hide") | |
.text(message); | |
setTimeout(function () { | |
$("#warning-popup") | |
.fadeOut(1000, function (e) { | |
$(this).addClass("hide").css("display", ""); | |
}); | |
}, 5000); | |
}, | |
init: function () { | |
$("<a></a>").attr("href", "#1").text("#1").click(function (event) { | |
$("#src-url").click().val("https://raw.githubusercontent.com/Lunatrius/InGame-Info-XML/master/src/main/resources/assets/ingameinfo/lang/en_US.lang"); | |
$("#dst-url").click().val("https://raw.githubusercontent.com/Lunatrius/InGame-Info-XML/master/src/main/resources/assets/ingameinfo/lang/no_NO.lang"); | |
$("#src-url").change(); | |
$("#load").click(); | |
return false; | |
}).appendTo("#examples"); | |
$("<a></a>").attr("href", "#2").text("#2").click(function (event) { | |
$("#src-text").click().val("# example\nexamplemod.gui.title=Example Mod\nexamplemod.gui.done=Done\nexamplemod.gui.yes=Yes\nexamplemod.gui.no=No\n"); | |
$("#dst-text").click().val("# this shouldn't be here!\nexamplemod.gui.title_typo=Invalid Key\nexamplemod.gui.done=\n\nexamplemod.gui.no=Ne\n"); | |
$("#src-text").change(); | |
$("#load").click(); | |
return false; | |
}).appendTo("#examples"); | |
$.each(["src", "dst"], function (index, origin) { | |
$.each(["url", "text"], function (index, type) { | |
$("#" + origin + "-" + type).click(function (event) { | |
$("#" + origin + "-" + type + "-type").click(function (event) { | |
data[origin + "Type"] = $(event.target).val(); | |
}); | |
$("#" + origin + "-" + type + "-type").click(); | |
}); | |
}); | |
}); | |
$("#src-url").click(); | |
$("#dst-url").click(); | |
$("#loadlast").prop("disabled", localStorage.length === 0); | |
$("#github-files").change(function (event) { | |
$("#src-url").val($(event.target).val().replace(/[a-z]+_[A-Z]+\.lang$/, "en_US.lang")).change(); | |
$("#dst-url").val($(event.target).val()).change(); | |
}); | |
$("#github-list-select").change(function (event) { | |
$("#src-url").val($(event.target).val().replace(/[a-z]+_[A-Z]+\.lang$/, "en_US.lang")).change(); | |
$("#dst-url").val($(event.target).val()).change(); | |
}); | |
$("#github-load").click(function (event) { | |
var match = $("#github-repo").val().match(/github.com\/([^\/]+)\/([^\/]+)(?:\/tree\/?([^\/]+)?)?/); | |
var url, user, repo, master; | |
if (match) { | |
user = match[1]; | |
repo = match[2]; | |
master = match[3] ? match[3] : "master"; | |
url = "https://api.github.com/repos/" + user + "/" + repo + "/git/trees/" + master + "?recursive=1"; | |
} | |
if (url) { | |
this.getText(url, function (data) { | |
if (data.success) { | |
var json = JSON.parse(data.text); | |
$("#github-files-src").html(""); | |
$("#github-files-dst").html(""); | |
$.each(json.tree, function (index, obj) { | |
if (/\.lang$/i.test(obj.path)) { | |
$("<option></option>") | |
.val("https://raw.githubusercontent.com/" + user + "/" + repo + "/" + master + "/" + obj.path) | |
.text(obj.path) | |
.appendTo((/en_US\.lang/i.test(obj.path)) ? "#github-files-src" : "#github-files-dst"); | |
} | |
}); | |
$("#github-files").trigger("chosen:updated"); | |
$("#github-files").change(); | |
} else { | |
this.callbackFailed(data.text); | |
} | |
}.bind(this)); | |
} | |
}.bind(this)); | |
$("#load").click(function (event) { | |
var src = $(data.srcType === "url" ? "#src-url" : "#src-text"); | |
var dst = $(data.dstType === "url" ? "#dst-url" : "#dst-text"); | |
if (src.val().length === 0) { | |
alert("Please specify a source file."); | |
return; | |
} | |
if ($("#output:visible").size() === 1 && $("#output:visible").val().length > 0) { | |
if (!confirm("WARNING! Loading new files will override your changes.\nMake sure you save your changes first!")) { | |
return; | |
} | |
} | |
$("#output-container").addClass("hide"); | |
data.source = null; | |
data.target = null; | |
if (data.srcType === "url") { | |
this.getText(src.val(), function (e) { | |
data.source = e.success ? this.parse(e.text) : false; | |
this.process(); | |
}.bind(this)); | |
} else { | |
data.source = this.parse(src.val()); | |
this.process(); | |
} | |
if (data.dstType === "url") { | |
this.getText(dst.val(), function (e) { | |
data.target = e.success ? this.parse(e.text) : false; | |
this.process(); | |
}.bind(this)); | |
var match = dst.val().match(/\/([a-z]+_[A-Z]+)\.lang$/i); | |
if (match) { | |
$("#lang").val(match[1]).trigger("chosen:updated"); | |
} | |
} else { | |
data.target = this.parse(dst.val()); | |
this.process(); | |
} | |
window.onbeforeunload = function () { | |
return "You have unsaved changes! Are you sure?"; | |
}; | |
}.bind(this)); | |
$("#generate").click(function (event) { | |
this.generate(); | |
$("#output-container").removeClass("hide"); | |
window.onbeforeunload = null; | |
}.bind(this)); | |
$("#save").click(function (event) { | |
try { | |
saveAs(new Blob([$("#output").val()], { | |
"type": "text/plain;charset=utf-8" | |
}), $("#lang").val() + ".lang"); | |
} catch (e) { | |
alert("Something went wrong :(\n\n" + e); | |
} | |
window.onbeforeunload = null; | |
}); | |
$("#reset").click(function (event) { | |
if (confirm("WARNING! This will clear the cache and reset the website.\n\nAre you sure?")) { | |
localStorage.clear(); | |
$("#src-url,#dst-url").val("").click().change(); | |
$("#src-text,#dst-text").val(""); | |
$("#container").text(""); | |
$("#generate").prop("disabled", true); | |
$("#loadlast").prop("disabled", localStorage.length === 0); | |
$("#output-container").addClass("hide"); | |
} | |
window.onbeforeunload = null; | |
}); | |
$("#loadlast").click(function (event) { | |
if ($("#output:visible").size() === 1 && $("#output:visible").val().length > 0) { | |
if (!confirm("WARNING! Loading new files will override your changes.\nMake sure you save your changes first!")) { | |
return; | |
} | |
} | |
$("#output-container").addClass("hide"); | |
for (var i = 0; i < localStorage.length; i++) { | |
var id = localStorage.key(i); | |
var node = $("#" + id); | |
node.val(localStorage.getItem(id)); | |
if (/\-text/.test(node.attr("id")) && node.val().length > 0) { | |
node.click(); | |
} | |
} | |
$("#load").click(); | |
}); | |
if (location.search.length > 0) { | |
var search = location.search.replace(/^\?+/, ""); | |
var load = false; | |
var path = null; | |
$.each(search.split("&"), function (index, part) { | |
var split = part.split("="); | |
if (split.length === 2 && /^(src|dst)$/.test(split[0])) { | |
var loc = decodeURI(split[1]); | |
if (loc.substr(0, 2) === "./") { | |
if (path !== null) { | |
loc = loc.replace("./", path); | |
} else { | |
return; | |
} | |
} | |
$("#" + split[0] + "-url").val(loc); | |
path = loc.substr(0, loc.lastIndexOf("/") + 1); | |
load = true; | |
} | |
if (split.length === 2 && split[0] === "repo") { | |
var loc = decodeURI(split[1]); | |
var match = loc.match(/github.com\/([^\/]+)\/([^\/]+)(?:\/tree\/?([^\/]+)?)?/); | |
var url, user, repo, master; | |
if (match) { | |
user = match[1]; | |
repo = match[2]; | |
master = match[3] ? match[3] : "master"; | |
url = "https://api.github.com/repos/" + user + "/" + repo + "/git/trees/" + master + "?recursive=1"; | |
} | |
if (url) { | |
this.getText(url, function (data) { | |
if (data.success) { | |
var files = {}; | |
var json = JSON.parse(data.text); | |
$("#github-list").removeClass("hide"); | |
$.each(json.tree, function (index, obj) { | |
if (/\.lang$/i.test(obj.path)) { | |
var index = obj.path.lastIndexOf("/"); | |
var path = obj.path.substr(0, index); | |
var name = obj.path.substr(index + 1).replace(/\.lang/i, ""); | |
if (!(files[path] instanceof Array)) { | |
files[path] = []; | |
} | |
files[path].push(name); | |
} | |
}); | |
$.each(files, function (path, langs) { | |
var optgroup = $("<optgroup></optgroup>") | |
.attr({ | |
"label": path | |
}) | |
.appendTo("#github-list-select"); | |
$("#lang option").each(function (index, element) { | |
$("<option></option>") | |
.addClass($.inArray($(element).val(), langs) !== -1 ? "file" : "nofile") | |
.text($(element).text()) | |
.val("https://raw.githubusercontent.com/" + user + "/" + repo + "/" + master + "/" + path + (path.length > 0 ? "/" : "") + $(element).val() + ".lang") | |
.appendTo(optgroup); | |
}); | |
optgroup | |
.find("option") | |
.sort(function (a, b) { | |
var c = $(b).hasClass("file") - $(a).hasClass("file"); | |
if (c !== 0) { | |
return c; | |
} | |
return $(a).text() > $(b).text(); | |
}) | |
.appendTo(optgroup); | |
}); | |
$("#github-list-select").chosen(); | |
$("#github, #github-load").addClass("hide"); | |
$("#github-list-link").attr("href", "https://github.com/" + user + "/" + repo + "/tree/" + master); | |
} else { | |
this.callbackFailed(data.text); | |
} | |
}.bind(this)); | |
} | |
} | |
}.bind(this)); | |
if (load) { | |
$("#load").click(); | |
} | |
} | |
$("#src-url,#dst-url").change(function(event) { | |
var src = $("#src-url").val(); | |
var dst = $("#dst-url").val(); | |
var args = []; | |
if (src.length > 0) { | |
args.push("src=" + encodeURI(src)); | |
if (dst.length > 0) { | |
var last = src.lastIndexOf("/"); | |
if (src.substr(0, last + 1) === dst.substr(0, last + 1)) { | |
dst = "." + dst.substr(last); | |
} | |
args.push("dst=" + encodeURI(dst)); | |
} | |
$("#permalink-container").removeClass("hide"); | |
$("#permalink").val(location.origin + location.pathname + "?" + args.join("&")); | |
} else { | |
$("#permalink-container").addClass("hide"); | |
} | |
}).change(); | |
$("#lang").chosen({ | |
"width": "250px" | |
}); | |
$("#github-files").chosen({ | |
"width": "auto" | |
}); | |
return this; | |
}, | |
tooltip: function (str) { | |
var ret = []; | |
var modifier = false; | |
var color = false; | |
var obf = false; | |
var bold = false; | |
var strikethrough = false; | |
var underlined = false; | |
var italic = false; | |
for (var i = 0, c; i < str.length; i++) { | |
c = str.charAt(i); | |
if (c === "<") c = "<"; | |
if (c === ">") c = ">"; | |
if (modifier && c === "r") { | |
if (color) { | |
ret.push("</span>"); | |
} | |
if (obf) { | |
ret.push("</obf>"); | |
} | |
if (bold) { | |
ret.push("</b>"); | |
} | |
if (strikethrough) { | |
ret.push("</s>"); | |
} | |
if (underlined) { | |
ret.push("</u>"); | |
} | |
if (italic) { | |
ret.push("</i>"); | |
} | |
color = false; | |
obf = false; | |
bold = false; | |
strikethrough = false; | |
underlined = false; | |
italic = false; | |
modifier = false; | |
continue; | |
} | |
if (modifier) { | |
if (/[0-9a-f]/i.test(c)) { | |
if (color) { | |
ret.push("</span>"); | |
} | |
color = true; | |
ret.push("<span class='color-" + c + "'>"); | |
} | |
if (c === "k") { | |
obf = true; | |
ret.push("<obf>"); | |
} | |
if (c === "l") { | |
bold = true; | |
ret.push("<b>"); | |
} | |
if (c === "m") { | |
strikethrough = true; | |
ret.push("<s>"); | |
} | |
if (c === "n") { | |
underlined = true; | |
ret.push("<u>"); | |
} | |
if (c === "o") { | |
italic = true; | |
ret.push("<i>"); | |
} | |
modifier = false; | |
continue; | |
} | |
modifier = c === "§"; | |
if (!modifier) { | |
ret.push(c); | |
} | |
} | |
return this.pre(ret.join(""), true); | |
}, | |
noenterKeypress: function (event) { | |
if (event.keyCode === 13) { | |
return false; | |
} | |
}, | |
noenterKeyup: function (event) { | |
var textarea = $(this); | |
textarea.val(textarea.val().replace(/[\r\n]+/g, "")); | |
this.style.height = 0; | |
this.style.height = this.scrollHeight + "px"; | |
}, | |
pre: function (str, skip) { | |
if (skip !== true) { | |
str = str.replace(/</g, "<").replace(/>/g, ">"); | |
} | |
str = str.replace(/([^\s]{75,})/, function (match, _, index, str) { | |
var arr = []; | |
while (match.length > 75) { | |
arr.push(match.substr(0, 75)); | |
match = match.substr(75); | |
} | |
if (match.length > 0) { | |
arr.push(match); | |
} | |
return arr.join(" <span style='font-weight:bold;'>[LONG_WORD_FORCED_BREAK]</span> "); | |
}); | |
return str.replace(/(^ {1,}| {1,}$| {2,})/, function (match, _, index, str) { | |
return "<span class='pre'>" + match + "</span>"; | |
}); | |
}, | |
updateProgress: function () { | |
var textareas = $("#container textarea"); | |
var textareasDone = textareas.filter(function() { | |
return $(this).val().length > 0; | |
}); | |
$("#container>p.notice").text("Progress: " + textareasDone.size() + "/" + textareas.size() + " "); | |
if (textareasDone.size() < textareas.size()) { | |
$("<a></a>") | |
.attr({ | |
"href": "#" | |
}) | |
.text("Next") | |
.click(function () { | |
var el = $("#container textarea") | |
.filter(function () { | |
return $(this).val().length === 0; | |
}) | |
.eq(0) | |
.select(); | |
$('html, body').animate({ | |
scrollTop: el.offset().top - 20 | |
}, 1000); | |
return false; | |
}) | |
.appendTo("#container>p.notice"); | |
} | |
}, | |
generate: function () { | |
var output = []; | |
var ignoreSame = $("#ignore-same").prop("checked"); | |
$.each(data.source.entries, function (index, entry) { | |
if (entry.type === TYPE_COMMENT || entry.type === TYPE_BLANK) { | |
output.push(entry.value); | |
} else { | |
var val = $("#" + entry.value.replace(/[^\w]/g, "_")).val(); | |
if (val && val.length > 0 && (!ignoreSame || data.source.mapping[entry.value] !== val)) { | |
output.push(entry.value + "=" + val); | |
} | |
} | |
}); | |
$("#output").val(output.join("\n")); | |
$("#src-url,#dst-url,#src-text,#dst-text,#output").each(function(index, node) { | |
var id = $(node).attr("id"); | |
if (id === "output") { | |
id = "dst-text"; | |
} | |
localStorage[id] = $(node).val(); | |
}); | |
$("#loadlast").prop("disabled", false); | |
}, | |
process: function () { | |
if (data.source === null || data.target === null) { | |
$("#container").text("Loading..."); | |
} else if (data.source === false) { | |
$("#container").text(""); | |
this.warning("source could not be loaded!"); | |
} else { | |
profiler.start("stuff"); | |
$("#container").text(""); | |
if (data.target === false && data.dstType === "url" && $("#dst-url").val().length > 0) { | |
this.warning("target could not be loaded."); | |
} | |
$("#generate").prop("disabled", false); | |
this.notice("Notice me senpai!"); | |
var table = $("<table></table>").attr("id", "table"); | |
$("<tr></tr>") | |
.append($("<th></th>").text("Source")) | |
.append($("<th></th>").text("Target")) | |
.appendTo(table); | |
profiler.endStart("generate"); | |
$.each(data.source.entries, function (index, entry) { | |
var tr = $("<tr></tr>").appendTo(table); | |
if (entry.type === TYPE_COMMENT) { | |
$("<td></td>").attr("colspan", 2).addClass("comment").html(this.pre(entry.value)).appendTo(tr); | |
} else if (entry.type === TYPE_BLANK) { | |
$("<td></td>").attr("colspan", 2).html(" ").appendTo(tr); | |
} else if (entry.type === TYPE_ENTRY) { | |
$("<td></td>").attr("title", entry.value + "<hr />" + this.tooltip(data.source.mapping[entry.value])).html(this.pre(data.source.mapping[entry.value])).appendTo(tr); | |
$("<td></td>").append( | |
$("<textarea></textarea>") | |
.attr({ | |
"id": entry.value.replace(/[^\w]/g, "_"), | |
"placeholder": data.source.mapping[entry.value] | |
}) | |
.prop("required", true) | |
.val(data.target && data.target.mapping[entry.value] || "") | |
.keypress(this.noenterKeypress) | |
.keyup(this.noenterKeyup) | |
.keyup(this.updateProgress) | |
.blur(this.generate) | |
).appendTo(tr); | |
} | |
}.bind(this)); | |
profiler.endStart("append"); | |
// append when done for extra speed | |
$("#container").append(table); | |
profiler.endStart("resize"); | |
// need this workaround to prevent constant re-layouting | |
// diesieben07 <3 | |
$("#table textarea").each(function (index, node) { | |
$(node).data("actual-height", node.scrollHeight); | |
}); | |
$("#table").css("display", "none"); | |
$("#table textarea").each(function (index, node) { | |
node.style.height = $(node).data("actual-height") + "px"; | |
}); | |
$("#table").css("display", ""); | |
profiler.endStart("update"); | |
this.updateProgress(); | |
profiler.end(); | |
} | |
} | |
}.init(); | |
$(function() { | |
$(document).tooltip({ | |
content: function () { | |
return $(this).attr("title"); | |
} | |
}); | |
}); | |
if (location.hostname !== "mc.lunatri.us") { | |
if (location.hostname === "dl.dropboxusercontent.com") { | |
$("<p>This is the development version of the translation tool and may be broken. Go to <a href='http://mc.lunatri.us/translate'>http://mc.lunatri.us/translate</a> for the release version.</p>").addClass("notice").prependTo("body"); | |
} else { | |
$("<p>This is a mirror of the translation tool from <a href='http://mc.lunatri.us/translate'>http://mc.lunatri.us/translate</a>.</p>").addClass("notice").prependTo("body"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@warning: rgb(255, 0, 0); | |
@warning2: rgb(255, 165, 0); | |
@notice: rgb(63, 63, 255); | |
@fontsize: 11pt; | |
@fontfamily: "Helvetica Neue", Helvetica, Arial, sans-serif; | |
.box(@color, @percent) { | |
font-weight: bold; | |
color: @color; | |
border: 1px solid @color; | |
background-color: lighten(@color, @percent); | |
padding: 5pt; | |
} | |
.nofile { | |
&.highlighted { | |
color: lighten(@warning, 30%) !important; | |
} | |
color: @warning; | |
} | |
.file { | |
&.highlighted { | |
color: lighten(@warning2, 30%) !important; | |
} | |
color: @warning2; | |
} | |
.warning { | |
.box(@warning, 40%); | |
} | |
.notice { | |
.box(@notice, 30%); | |
} | |
.comment { | |
font-weight: bold; | |
} | |
.hide { | |
display: none; | |
} | |
.pre { | |
white-space: pre; | |
background-color: #DDDDDD; | |
} | |
body { | |
font-size: @fontsize; | |
font-family: @fontfamily; | |
} | |
table { | |
&#input { | |
input[type="text"], | |
table#input textarea { | |
width: 95%; | |
} | |
textarea { | |
height: 5em; | |
} | |
} | |
&#table { | |
textarea { | |
&:invalid { | |
background-color: hsla(0, 90%, 95%, 1); | |
} | |
&:valid { | |
background-color: hsla(100, 90%, 95%, 1); | |
} | |
width: 100%; | |
height: 1.0em; | |
border: 1px solid #BFBFBF; | |
word-wrap: break-word; | |
} | |
tr td { | |
border-bottom: 1px solid #DDDDDD; | |
word-wrap: break-word; | |
} | |
th { | |
width: 50%; | |
} | |
} | |
tr td:first-child { | |
width: 150px; | |
} | |
width: 100%; | |
} | |
textarea { | |
&#output { | |
background-color: #EEEEEE; | |
} | |
&#input, | |
&#output { | |
height: 15em; | |
} | |
width: 100%; | |
font-size: 1em; | |
font-family: @fontfamily; | |
resize: vertical; | |
} | |
div.ui-tooltip { | |
font-size: 1em; | |
max-width: 50%; | |
} | |
.color-0 { color: #000000; } | |
.color-1 { color: #0400AA; } | |
.color-2 { color: #02AA01; } | |
.color-3 { color: #05AAAA; } | |
.color-4 { color: #AA0000; } | |
.color-5 { color: #AA00AA; } | |
.color-6 { color: #FFAA02; } | |
.color-7 { color: #AAAAAA; } | |
.color-8 { color: #555555; } | |
.color-9 { color: #5654FF; } | |
.color-a { color: #56FF55; } | |
.color-b { color: #57FFFF; } | |
.color-c { color: #FF5555; } | |
.color-d { color: #FF55FF; } | |
.color-e { color: #FFFF56; background-color: #000000; } | |
.color-f { color: #FFFFFF; background-color: #000000; } | |
@-webkit-keyframes obfuscated { | |
0% { opacity: 0; } | |
50% { opacity: 1; } | |
100% { opacity: 0; } | |
} | |
@-moz-keyframes obfuscated { | |
0% { opacity: 0; } | |
50% { opacity: 1; } | |
100% { opacity: 0; } | |
} | |
@-o-keyframes obfuscated { | |
0% { opacity: 0; } | |
50% { opacity: 1; } | |
100% { opacity: 0; } | |
} | |
@keyframes obfuscated { | |
0% { opacity: 0; } | |
50% { opacity: 1; } | |
100% { opacity: 0; } | |
} | |
obf { | |
-webkit-animation: obfuscated 0.5s infinite; | |
-moz-animation: obfuscated 0.5s infinite; | |
-o-animation: obfuscated 0.5s infinite; | |
animation: obfuscated 0.5s infinite; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment