0
我在我的應用程序中使用Google音譯。谷歌在關鍵字上的音譯
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("elements", "1", { packages: "transliteration" });
</script>
<script>
function OnLoad() {
var options = {
sourceLanguage:
google.elements.transliteration.LanguageCode.ENGLISH,
destinationLanguage:
[google.elements.transliteration.LanguageCode.TAMIL],
shortcutKey: 'ctrl+g',
transliterationEnabled: true
};
//farmer name
var control = new google.elements.transliteration.TransliterationControl(options);
control.makeTransliteratable(["txtFarmer_nameTn"]);
var keyVal = 32; // Space key
$("#txtFarmer_nameEng").on('keydown', function (event) {
if (event.keyCode === 32) {
var engText = $("#txtFarmer_nameEng").val() + " ";
var engTextArray = engText.split(" ");
$("#txtFarmer_nameTn").val($("#txtFarmer_nameTn").val() + engTextArray[engTextArray.length - 2]);
document.getElementById("txtFarmer_nameTn").focus();
$("#txtFarmer_nameTn").trigger(
{
type: 'keypress', keyCode: keyVal, which: keyVal, charCode: keyVal
});
}
var txt1 = document.getElementById("txtFarmer_nameEng").value;
if (txt1.length == 1) {
document.getElementById("txtFarmer_nameTn").value = "";
}
});
$("#txtFarmer_nameTn").bind("keyup", function (event) {
setTimeout(function() {
$("#txtFarmer_nameEng").val($("#txtFarmer_nameEng").val() + " ");
document.getElementById("txtFarmer_nameEng").focus()
}, 0);
});
}
google.setOnLoadCallback(OnLoad);
</script>
它也工作正常。但問題是文字只有在撞擊空格鍵後才被翻譯。我需要翻譯每個按鍵上的文字。
這裏是reference
請提出解決方案。我在谷歌漫遊,但我無法得到確切的解決方案。建議使用什麼來代替Google Transliterate API。
在此先感謝。
好的龐。我認爲你是對的,沒有選擇我在想什麼。 –