我想在按下按钮时使用Google Transliterate API将英语单词翻译成印地文和古吉拉特语(印度语言)。
我已推荐https://developers.google.com/transliterate/v1/getting_started编写如下代码。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
//Load the Language API.
google.load("language", "1");
var srcLang="en";
var destLang="hi";
function engConvert() {
var engText = document.getElementById("enText");
var result;
//Call google.language.transliterate()
google.language.transliterate([engText], srcLang, destLang, result);
document.getElementById("hiText").innerHTML = result;
}
</script>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container" style="margin-top: 20px">
<div class="row text-center">
<div class="col">English</div>
<div class="col">Hindi</div>
<div class="col">Gujarati</div>
</div>
<div class="row"> </div>
<div class="row text-center">
<div class="col"><input type="text" class="form-control" name="enText" id="enText"></div>
<div class="col"><input type="text" class="form-control" name="hiText" id="hiText"></div>
<div class="col"><input type="text" class="form-control" name="guText" id="guText"></div>
</div>
<div class="row"> </div>
<div class="row text-center">
<div class="col"></div>
<div class="col"></div>
<button type="button" class="col btn btn-primary" onclick="engConvert()">Transliterate</button>
<div class="col"></div>
<div class="col"></div>
</div>
</div>
</body>
</html>
但是我从音译函数中收到回调错误。我不是JS和使用API的专家,所以请指导我。