it/itf/static/js/mytrans.js

55 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2010-03-03 14:28:00 +00:00
google.load("elements", "1", {
packages: 'transliteration'
});
//google.load("language", "1"):
$(document).ready(function() {
var transElem = $('#id_translations-TOTAL_FORMS').parent();
transElem.remove();
var firstFormElem = $('.form-row:first');
firstFormElem.append(transElem);
//Add on blur to english field
$('#id_translations-0-firstname').blur(function() {
var strArr = $(this).val().split(" ");
google.language.transliterate(strArr, "en", "hi", function(result) {
if (!result.error) {
console.log(result);
}
});
});
$.getJSON("/getLanguages", {}, function(data) {
var myLanguages = data;
var destLangs = [];
var allTransIds = [];
for (var l in myLanguages) {
if (l >= 1) {
var lShort = myLanguages[l]['short']
destLangs.push(lShort);
var thisForm = transElem.find('.inline-related').eq(l);
thisForm.find('textarea, input').each(function() {
if ($(this).attr("type") != "hidden") {
var thisId = $(this).attr('id');
allTransIds.push(thisId);
$(this).attr("data-lang", lShort);
$(this).focus(function() {
var lang = $(this).attr("data-lang");
GControl.setLanguagePair("en", lang);
});
}
});
}
}
var options = {
sourceLanguage: 'en',
destinationLanguage: destLangs,
transliterationEnabled: true
}
GControl = new google.elements.transliteration.TransliterationControl(options);
GControl.makeTransliteratable(allTransIds);
});
});