Last active
April 29, 2020 15:10
-
-
Save YossiCohen/47e2301c1698e467c6c1c88803552c7c to your computer and use it in GitHub Desktop.
Simple language comparison tool - for those who want to translate Snap - (should be placed in the project root - next to index.html)
This file contains 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> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
</head> | |
<body> | |
<div> | |
<h1>Insert two languages to compare</h1> | |
<h3>i.e.: he,de</h3> | |
<span>First file:</span> | |
<input type="text" id="first-file" > | |
</div> | |
<div> | |
<span>Second file:</span> | |
<input type="text" id="second-file"> | |
</div> | |
<button id="btn">DIFF</button> | |
<div id="first-file-diff"></div> | |
<div id="second-file-diff"></div> | |
</body> | |
<script type="text/javascript"> | |
var SnapTranslator = {}; | |
SnapTranslator.dict = {}; | |
var firstLoaded = false; | |
var firstLang; | |
var secondLang; | |
function diff(A, B) { | |
return A.filter(function (a) { | |
return B.indexOf(a) == -1; | |
}); | |
}; | |
function loadTranslationFile(lang, pos) { | |
var fileref; | |
fileref = document.createElement("script"); | |
fileref.setAttribute("type", "text/javascript"); | |
fileref.setAttribute("src", 'locale/lang-'+lang+'.js'); | |
fileref.async = false; | |
if (fileref) { | |
document.getElementsByTagName("head")[0].appendChild(fileref); | |
} | |
fileref.onload = function () { | |
if (!firstLoaded){ | |
firstLoaded = true; | |
} else { | |
let firstFile = Object.keys(SnapTranslator.dict[firstLang]).sort(); | |
let secondFile = Object.keys(SnapTranslator.dict[secondLang]).sort(); | |
var heDiff = diff(secondFile,firstFile); | |
var deDiff = diff(firstFile,secondFile); | |
document.getElementById('first-file-diff').innerHTML = "<H2>Keys that appear in "+secondLang+" and missing in "+firstLang+"</H2>"+ "<p>" + heDiff.join("</p><p>") + "</p>"; | |
document.getElementById('second-file-diff').innerHTML = "<H2>Keys that appear in "+firstLang+" and missing in "+secondLang+"</H2>" +"<p>" + deDiff.join("</p><p>") + "</p>"; | |
} | |
} | |
}; | |
document.getElementById('btn').addEventListener('click', function () { | |
firstLoaded = false; | |
SnapTranslator = {}; | |
SnapTranslator.dict = {}; | |
firstLang = document.getElementById('first-file').value; | |
secondLang = document.getElementById('second-file').value; | |
loadTranslationFile(firstLang); | |
loadTranslationFile(secondLang); | |
}); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment