我一直在使用下面发布的代码来对按钮单击时的用户输入进行音译。但是,当运行代码并单击音译按钮时,我在浏览器的(firefox)控制台中得到了/* callback */google.language.callbacks.id100('22', null, 403, 'This API is no longer available.', 200)
响应。那么请告诉我们它的替代解决方案是什么?
代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google AJAX Language API - Basic Transliteration</title>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("language", "1");
google.load("elements", "1", { packages: "transliteration" });
function intialize_transliteration(){
var options = {
sourceLanguage: 'en',
destinationLanguage: ['kn'],
shortcutKey: 'ctrl+g',
transliterationEnabled: true
};
var control =
new google.elements.transliteration.TransliterationControl(options);
//add as many as required
var ids = [ "fnk", "lnk" ];
control.makeTransliteratable(ids);
control.showControl('translControl');
}
google.setOnLoadCallback(intialize_transliteration);
function tr() {
//Call google.language.transliterate()
google.language.transliterate(["asdas"], "en", "ur", function(result) {
var container = document.getElementById("fnk");
if (result.transliterations && result.transliterations.length > 0 &&
result.transliterations[0].transliteratedWords.length > 0) {
container.innerHTML = result.transliterations[0].transliteratedWords[0];
}
});
}
</script>
</head>
<body>
<br> First Name <input value="Thejesh Gangaiah" id="fn" />
<br> First Name (in Kannada) <input value="" id="fnk"/>
<br> Last Name <input value="Nagarathna" id="ln" />
<br> Last Name (in Kannada) <input value="" id="lnk"/>
<div id='translControl'></div>
<input type="button" onclick="tr()" value="transliterate"/>
</body>
</html>
答案 0 :(得分:1)
google音译API是deprecated in 2011,所以我认为,截至今天(2018年6月),根据他们的Deprecation Policy,它已经不复存在了。这意味着不能再使用了。问题不在于您的代码,而在于该服务变得不可用。