【发布时间】:2020-12-19 07:35:54
【问题描述】:
我这里有以下代码
<body>
<p id="textField">You can translate the <span class="notranslate" translate="no" >content of this page</span> by selecting a language in the select box.</p>
<h1 id="title">My Web Page</h1>
<p>Hello everybody!</p>
<p>Translate this page:</p>
<form>
<select id="targetLanguage">
<option value="en">English</option>
<option value="hi">Hindi</option>
</select>
<input type="button" id="translateButton" value="Translate" />
</form>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$("#translateButton").click(function () {
var url = "https://translation.googleapis.com/language/translate/v2";
//Strings requiring translation
url += "?q=" + $("#textField").text();
url += "&q=" + $("#title").text();
//Target language
url += "&target=" + $("#targetLanguage").val();
//Replace with your API key
url += "&key=API_KEY_if You need to test i can share";
$.get(url, function (data, status) {
//Results are returned in an array following the order they were passed.
$("#textField").text(data.data.translations[0].translatedText);
$("#title").text(data.data.translations[1].translatedText);
});
});
</script>
</body>
我想要的只是忽略没有翻译类的内容和 不要触摸或进入这些课程,但谷歌不听。
有什么办法可以解决这个问题吗??
【问题讨论】:
标签: google-api google-translate translate google-translation-api