javascript - 我需要将博客文章分块发送到谷歌翻译并返回
问题描述
我需要分块发送博客文章,最好是用句子或单词来翻译并返回我已经有了翻译功能我只需要帮助将它分成块并取回我如何才能做到这一点?
//["this","is","the","post"]
var bod = a.body.split(" ");
var counter = 0;
while(counter < bod.length){
counter++;
var rang = bod.slice(counter, 10);
//then translate the remaining portion with the code that is ready
console.log(rang);
if(counter === bod.length || counter > bod.length){
console.log("end");
return;
}
}
解决方案
你在正确的轨道上。
无需详细了解您对 google 的请求,请执行以下操作:
//Sample input
var body = 'The words I want to translate!';
//Sample result, will be an array containing translated words
var translated = translateData(body);
//Sample function
function translateData(body){
var bodyArray = body.split(' ');
var translatedData = [];
for(var i = 0;i<bodyArray.Length;i++){
//Do the translation here. var translated is the translation for the word
var translated = GoogleTranslate(bodyArray[i]);
translatedData.push(translated);
}
return translatedData;
}
推荐阅读
- php - SQL 错误 1064、42000 您的 SQL 语法有错误但无法发现问题
- azure - 如何为特定的 LUIS 意图 beginDialog?
- azure - 如何在 SAP WebIDE 和 HCP 中使用 Outlook OData?
- excel - UnMerge 在 Access VBA 中不起作用的原因是什么?
- php - MySQL/PHP else if 语句与受影响的行
- java - 如何将所有执行器启用到 Spring-MVC?
- android - 重新加载应用程序时启动错误的活动
- c# - 在 Windows Docker 容器中设置语言和区域设置
- angular - 清晰度 - 能够自定义数据网格组件的选择
- typescript - 用于生成实现接口的类的 Typescript 函数