mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
Refactor js translator to be able to share some code with the ajax version.
This commit is contained in:
@@ -6,6 +6,26 @@
|
|||||||
<script type="text/javascript" src="gflib.js"></script>
|
<script type="text/javascript" src="gflib.js"></script>
|
||||||
<script type="text/javascript" src="grammar.js"></script>
|
<script type="text/javascript" src="grammar.js"></script>
|
||||||
<script type="text/javascript" src="translator.js"></script>
|
<script type="text/javascript" src="translator.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
/* CHANGE ME */
|
||||||
|
var grammar = Food;
|
||||||
|
|
||||||
|
function updateTranslation () {
|
||||||
|
var input = document.getElementById('inputText').value;
|
||||||
|
var fromLang = document.getElementById('fromLang').value;
|
||||||
|
var toLang = document.getElementById('toLang').value;
|
||||||
|
addTranslation('output', grammar.translate(input, fromLang, toLang));
|
||||||
|
}
|
||||||
|
|
||||||
|
function populateLangs () {
|
||||||
|
var f = document.getElementById('fromLang');
|
||||||
|
var t = document.getElementById('toLang');
|
||||||
|
for (var c in grammar.concretes) {
|
||||||
|
addOption(f, c, c);
|
||||||
|
addOption(t, c, c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
<title>Web-based GF Translator</title>
|
<title>Web-based GF Translator</title>
|
||||||
</head>
|
</head>
|
||||||
<body onload="populateLangs(Food, 'fromLang', 'toLang')">
|
<body onload="populateLangs(Food, 'fromLang', 'toLang')">
|
||||||
@@ -16,7 +36,7 @@
|
|||||||
<p>
|
<p>
|
||||||
From: <select name="fromLang" id="fromLang" onchange=""><option value="">Any language</option></select>
|
From: <select name="fromLang" id="fromLang" onchange=""><option value="">Any language</option></select>
|
||||||
To: <select name="toLang" id="toLang"><option value="">All languages</option></select>
|
To: <select name="toLang" id="toLang"><option value="">All languages</option></select>
|
||||||
<input type="button" value="Translate" onclick="updateTranslation(Food, 'inputText','fromLang','toLang','output'); return false;" />
|
<input type="button" value="Translate" onclick="updateTranslation()" />
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
<div id="output"></div>
|
<div id="output"></div>
|
||||||
|
|||||||
@@ -1,18 +1,5 @@
|
|||||||
function updateTranslation (grammar, inputID, fromLangID, toLangID, outputID) {
|
function addTranslation (outputID, translation) {
|
||||||
var input = document.getElementById(inputID).value;
|
document.getElementById(outputID).appendChild(formatTranslation(translation));
|
||||||
var fromLang = document.getElementById(fromLangID).value;
|
|
||||||
var toLang = document.getElementById(toLangID).value;
|
|
||||||
var output = document.getElementById(outputID);
|
|
||||||
output.appendChild(formatTranslation(grammar.translate(input, fromLang, toLang)));
|
|
||||||
}
|
|
||||||
|
|
||||||
function populateLangs (grammar, fromLang, toLang) {
|
|
||||||
var f = document.getElementById(fromLang);
|
|
||||||
var t = document.getElementById(toLang);
|
|
||||||
for (var c in grammar.concretes) {
|
|
||||||
addOption(f, c, c);
|
|
||||||
addOption(t, c, c);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatTranslation (outputs) {
|
function formatTranslation (outputs) {
|
||||||
|
|||||||
Reference in New Issue
Block a user