【简介】

Azure Cognitive Services Translato 是一种基于云的神经网络机器翻译服务,同时也是 REST API 的 Azure 认知服务系列的一部分。
本篇文章将会主要介绍到我们如何使用NodeJS手动编写调用Azure Cognitive Services Translator API代码获取其支持翻译的语言集

【前期文章】

【Microsoft Azure 的1024种玩法】一.一分钟快速上手搭建宝塔管理面板
【Microsoft Azure 的1024种玩法】二.基于Azure云平台的安全攻防靶场系统构建
【Microsoft Azure 的1024种玩法】三.基于Azure云平台构建Discuz论坛
【Microsoft Azure 的1024种玩法】四. 利用Azure Virtual machines 打造个人专属云盘,速度吊打某云盘
【Microsoft Azure 的1024种玩法】五.基于Azure Cloud Shell 一站式创建Linux VM
【Microsoft Azure 的1024种玩法】六.使用Azure Cloud Shell对Linux VirtualMachines 进行生命周期管理
【Microsoft Azure 的1024种玩法】七.Azure云端搭建部署属于自己的维基百科
【Microsoft Azure 的1024种玩法】八. 基于Azure云端轻松打造一款好用的私有云笔记
【Microsoft Azure 的1024种玩法】九. Microsoft Azure云端轻松构建部署PostgreSQL数据库
【Microsoft Azure 的1024种玩法】十. 基于Azure App Service 快速上手部署 ASP.NET Web 应用
【Microsoft Azure 的1024种玩法】十一.手动对Azure磁盘进行IOPS性能压力测试
【Microsoft Azure 的1024种玩法】十二. 使用Auzre cloud 安装搭建docker+vulhub靶场
【Microsoft Azure 的1024种玩法】十三.Azure cloud|带你快速搭建DVWA靶场漏洞环境
【Microsoft Azure 的1024种玩法】十四.Azure DNS 在线域名委托解析操作指南
【Microsoft Azure 的1024种玩法】十五.通过Web浏览器对Auzre VM 服务器运维管理
【Microsoft Azure 的1024种玩法】十六.Cobaltstrike内网渗透工具在Azure Cloud中的部署使用
【Microsoft Azure 的1024种玩法】 十七.在Microsoft Azure上动手搭建专属私有文件同步服务]
【Microsoft Azure 的1024种玩法】 十八.快速创建Microsoft Azure SQL数据库初体验
【Microsoft Azure 的1024种玩法】 十九.使用Azure备份服务对虚拟机快速备份
【Microsoft Azure 的1024种玩法】 二十.Azure Multi-Factor Authentication多因素验证最佳实战
【Microsoft Azure 的1024种玩法】 二十一.利用Azure Blob Service 快速实现静态网站托管
【Microsoft Azure 的1024种玩法】 二十二.中国区Azure Cloud 多重身份验证最佳实践
【Microsoft Azure 的1024种玩法】 二十三.快速上手Azure Content Delivery Network 内容分发网络
【Microsoft Azure 的1024种玩法】二十四.通过Azure Front Door 的 Web 应用程序防火墙来对 OWASP TOP 10 威胁进行防御
【Microsoft Azure 的1024种玩法】 二十五.使用Azure CDN对Azure Blob 静态托管站点进行加速
【Microsoft Azure 的1024种玩法】二十六. 在Azure VM中手动部署Windows Admin Center管理平台
【Microsoft Azure 的1024种玩法】二十七. Azure Virtual Desktop虚拟桌面之快速创建配置(一)
【Microsoft Azure 的1024种玩法】二十八. 基于Azure Cloud搭建IPS入侵防御系统实现安全流量实时分析
【Microsoft Azure 的1024种玩法】二十九.基于Azure VM快速实现网络入侵检测 (IDS) 及网络安全监视 (NSM)
【Microsoft Azure 的1024种玩法】三十. 使用Azure Data Studio之快速上手连接管理Azure SQL 数据库(一)
【Microsoft Azure 的1024种玩法】三十一.使用Azure Logic App 创建基于计划定期执行邮件发送的自动化工作流
【Microsoft Azure 的1024种玩法】三十二. 利用 AzCopy来对Azure Blob Storage中的数据进行复制迁移
【Microsoft Azure 的1024种玩法】三十三.十分钟快速部署 Azure Kubernetes Service 群集
【Microsoft Azure 的1024种玩法】三十四.将本地数据文件快速迁移到Azure Blob云存储最佳实践
【Microsoft Azure 的1024种玩法】三十五.在Azure Virtual machines中手动部署Java Web
【Microsoft Azure 的1024种玩法】三十六.通过网络文件系统NFS协议快速将Blob 存储挂在Azure Virtual machines中
【Microsoft Azure 的1024种玩法】三十七.通过Azure Virtual Machines实现远程连接本地内网服务器(内网穿透)
【Microsoft Azure 的1024种玩法】三十八.通过Azure Function App函数应用实现对Azure Virtual Machines定时开关机
【Microsoft Azure 的1024种玩法】三十九.使用Auzre Media Services实现在线实时视频直播
【Microsoft Azure 的1024种玩法】四十.快速将阿里云DNS解析平滑迁移至Azure Zone实战操作
【Microsoft Azure 的1024种玩法】四十一. 将Windows Admin Center 网关注册到 Azure
【Microsoft Azure 的1024种玩法】四十二. 通过Windows Admin Center快速创建Azure Virtual Machines
【Microsoft Azure 的1024种玩法】四十三. 基于Azure云平台构建RTMP直播服务
【Microsoft Azure 的1024种玩法】四十五.在Azure中快速创建Azure AD Domain Services
【Microsoft Azure 的1024种玩法】四十六.将 Azure VM 实例添加到Azure AD Domain Service中
【Microsoft Azure 的1024种玩法】四十七.通过Azure Virtual machines搭建FTP应用服务
【Microsoft Azure 的1024种玩法】四十八.基于Azure Virtual Machines快速搭建SQL Server应用
【Microsoft Azure 的1024种玩法】四十九.在Azure中使用Azure VirtualMachines 搭建Microsoft SharePoint 2016
【Microsoft Azure 的1024种玩法】五十. 通过Azure文件共享将Azure File 挂载到本地机器实现文件实时共享
【Microsoft Azure 的1024种玩法】五十一.在Azure Virtual Machines 上装载 SMB Azure 文件共享
【Microsoft Azure 的1024种玩法】五十二.基于Azure Application Insight对Web应用进行实时链路跟踪
【Microsoft Azure 的1024种玩法】五十三.针对Azure Application Insight监控的应用程序指标配置不同维度的自动化报警通知
【Microsoft Azure 的1024种玩法】五十四. 十分钟快速上手创建部署Azure speech服务
【Microsoft Azure 的1024种玩法】五十五.Azure speech service之通过JavaScript快速实现文本转换为语音
【Microsoft Azure 的1024种玩法】五十六.使用Node.js对Azure blob进行生命周期管理
【Microsoft Azure 的1024种玩法】五十七.通过自定义映像批量创建Azure Virtual machines实现集群业务快速部署
【Microsoft Azure 的1024种玩法】五十八.基于Azure云平台快速构建开源任务管理工具
【Microsoft Azure 的1024种玩法】五十九.基于Azure云平台快速搭建GitLab应用实现代码托管
【Microsoft Azure 的1024种玩法】六十.通过Azure Virtual Machines快速搭建个人Ghost博客系统
【Microsoft Azure 的1024种玩法】六十一.通过Microsoft Azure Virtual Machines快速搭建消息队列RabbitMQ
【Microsoft Azure 的1024种玩法】六十二.利用Azure Private DNS 实现虚拟网络中域名的管理解析
【Microsoft Azure 的1024种玩法】六十三.通过全局 VNet 对等互连实现同一区域不同网段的虚拟网络实时打通
【Microsoft Azure 的1024种玩法】六十四.通过Azure Pass平台服务应用专用链接与虚拟网络进行全局VNet 对等互连实现数据安全防护
【Microsoft Azure 的1024种玩法】六十五.基于CloudShell在Azure Ubuntu VM中快速安装构建Jenkins应用
【Microsoft Azure 的1024种玩法】六十六.在Jenkins应用中通过Azure VM扩展集代理程式外挂程式执行Azure资源服务创建
【Microsoft Azure 的1024种玩法】六十七.通过Data Migration Assistant 将本地自建SQL Server 数据库脱机迁移至Azure SQL Database
【Microsoft Azure 的1024种玩法】六十八.基于Azure云平台快速搭建Docker容器
【Microsoft Azure 的1024种玩法】六十九.通过SSMS将本地自建SQL Server 数据库脱机迁移至Azure SQL Database
【Microsoft Azure 的1024种玩法】七十.通过Azure Portal将本地自建SQL Server 数据库在线导入至Azure SQL Database中
【Microsoft Azure 的1024种玩法】七十一.基于Azure Virtual Machines快速上手搭建Typecho博客系统
【Microsoft Azure 的1024种玩法】七十二.使用NodeJS编写调用Azure Cognitive Services Translator API代码获取其支持翻译的语言列表

【操作步骤】

一.在VS Code 中初始化项目环境

1.使用如下命令初始化创建的项目

npm init -y

具体操作,如下图所示


2.初始化完毕以后,如下图所示,会生成一个名为“package.json"的文件

3.我们新建一个用于配置调用API接口的index.js文件
4.使用npm安装Request依赖库

二.编写获取支持翻译语言列表的API代码

1.如下所示为Azure Cognitive Services Translator 支持翻译的语言集的API请求参数说明

参数 说明
api-version 客户端所请求的 API 的版本
scope 逗号分隔的名称列表,用于定义要返回的语言组

2.我们在VScode中编写如下代码来调用Azure Cognitive Services Translator API,其中 request中为1中的Azure Cognitive Services Translator API请求参数

const request = require('request')
const fs = require('fs')
const getList = () => {request('https://api.cognitive.microsofttranslator.com/languages?api-version=3.0', function (err, res, body) {if (err !== null) {console.log('error is:', err)} else {fs.writeFileSync('./languages.json', body, {encoding: 'utf-8'})console.log('语言支持列表已写入:./languages.json')}})
}
// 获取支持翻译语言列表
getList()

3.调用代码编写完毕后,我们使用node index.js 执行获取Azure Cognitive Services Translator所支持的翻译语言列表,执行完毕以后,我们可以在"languages.json"中看到具体支持的翻译语言列表

node index.js


4.如下图所示,我们获取到的语言支持列表文件

三.响应正文分析及列出支持翻译的语言集

1.通过API的方式调用成功的响应是一个 JSON 对象,其中包含请求的每个组的一个属性,如下图所示:

其中每个属性的值有不同的定义:

  • translation 属性

属性的值是 (键, 值) 对的字典。 每个键是一个 BCP 47 语言标记。 键标识文本的翻译目标语言或源语言。

{"translation": {"af": {"name": "Afrikaans","nativeName": "Afrikaans","dir": "ltr"},"am": {"name": "Amharic","nativeName": "አማርኛ","dir": "ltr"},"ar": {"name": "Arabic","nativeName": "العربية","dir": "rtl"},}
}
  • transliteration 属性

transliteration 属性的值是 (键, 值) 对的字典。 每个键是一个 BCP 47 语言标记。
键标识某种语言,该语言的文本可以从一个脚本转换为另一个脚本。

{"transliteration": {..."ja": {"name": "Japanese","nativeName": "日本語","scripts": [{"code": "Jpan","name": "Japanese","nativeName": "日本語","dir": "ltr","toScripts": [{"code": "Latn","name": "Latin","nativeName": "ラテン語","dir": "ltr"}]},{"code": "Latn","name": "Latin","nativeName": "ラテン語","dir": "ltr","toScripts": [{"code": "Jpan","name": "Japanese","nativeName": "日本語","dir": "ltr"}]}]},...}
}
  • dictionary 属性

dictionary 属性的值是 (键, 值) 对的字典。 每个键是一个 BCP 47 语言标记。 键标识支持替代翻译和回译的语言。

"es": {"name": "Spanish","nativeName": "Español","dir": "ltr","translations": [{"name": "English","nativeName": "English","dir": "ltr","code": "en"}]
},

2.最终通过Azure Cognitive Services Translator 的API接口所获取到支持翻译的语言列表如下所示

{"translation": {"af": {"name": "Afrikaans","nativeName": "Afrikaans","dir": "ltr"},"am": {"name": "Amharic","nativeName": "አማርኛ","dir": "ltr"},"ar": {"name": "Arabic","nativeName": "العربية","dir": "rtl"},"as": {"name": "Assamese","nativeName": "অসমীয়া","dir": "ltr"},"az": {"name": "Azerbaijani","nativeName": "Azərbaycan","dir": "ltr"},"ba": {"name": "Bashkir","nativeName": "Bashkir","dir": "ltr"},"th": {"name": "Thai","nativeName": "ไทย","scripts": [{"code": "Thai","name": "Thai","nativeName": "ภาษาไทย","dir": "ltr","toScripts": [{"code": "Latn","name": "Latin","nativeName": "ละติน","dir": "ltr"}]}]},"tt": {"name": "Tatar","nativeName": "Татар","scripts": [{"code": "Cyrl","name": "Cyrillic","nativeName": "Cyrillic","dir": "ltr","toScripts": [{"code": "Latn","name": "Latin","nativeName": "Latin","dir": "ltr"}]},{"code": "Latn","name": "Latin","nativeName": "Latin","dir": "ltr","toScripts": [{"code": "Cyrl","name": "Cyrillic","nativeName": "Cyrillic","dir": "ltr"}]}]},"uk": {"name": "Ukrainian","nativeName": "Українська","scripts": [{"code": "Cyrl","name": "Cyrillic","nativeName": "Кирилиця","dir": "ltr","toScripts": [{"code": "Latn","name": "Latin","nativeName": "латиниця","dir": "ltr"}]},{"code": "Latn","name": "Latin","nativeName": "латиниця","dir": "ltr","toScripts": [{"code": "Cyrl","name": "Cyrillic","nativeName": "Кирилиця","dir": "ltr"}]}]},"ur": {"name": "Urdu","nativeName": "اردو","scripts": [{"code": "Arab","name": "Arabic","nativeName": "Arabic","dir": "rtl","toScripts": [{"code": "Latn","name": "Latin","nativeName": "Latin","dir": "ltr"}]},{"code": "Latn","name": "Latin","nativeName": "Latin","dir": "ltr","toScripts": [{"code": "Arab","name": "Arabic","nativeName": "Arabic","dir": "rtl"}]}]},"zh-Hans": {"name": "Chinese Simplified","nativeName": "中文 (简体)","scripts": [{"code": "Hans","name": "Simplified","nativeName": "简体汉语","dir": "ltr","toScripts": [{"code": "Latn","name": "Latin","nativeName": "拉丁语","dir": "ltr"},{"code": "Hant","name": "Hat","nativeName": "传统","dir": "ltr"}]},{"code": "Latn","name": "Latin","nativeName": "拉丁语","dir": "ltr","toScripts": [{"code": "Hans","name": "Han","nativeName": "简体汉语","dir": "ltr"},{"code": "Hant","name": "Hat","nativeName": "传统","dir": "ltr"}]}]},"zh-Hant": {"name": "Chinese Traditional","nativeName": "繁體中文 (繁體)","scripts": [{"code": "Hant","name": "Traditional","nativeName": "傳統","dir": "ltr","toScripts": [{"code": "Latn","name": "Latin","nativeName": "拉丁语","dir": "ltr"},{"code": "Hans","name": "Han","nativeName": "简体汉语","dir": "ltr"}]},{"code": "Latn","name": "Latin","nativeName": "拉丁文","dir": "ltr","toScripts": [{"code": "Hans","name": "Han","nativeName": "简体汉语","dir": "ltr"},{"code": "Hant","name": "Hat","nativeName": "传统","dir": "ltr"}]}]}},"dictionary": {"af": {"name": "Afrikaans","nativeName": "Afrikaans","dir": "ltr","translations": [{"name": "English","nativeName": "English","dir": "ltr","code": "en"}]},"ar": {"name": "Arabic","nativeName": "العربية","dir": "rtl","translations": [{"name": "English","nativeName": "English","dir": "ltr","code": "en"}]},"bg": {"name": "Bulgarian","nativeName": "Български","dir": "ltr","translations": [{"name": "English","nativeName": "English","dir": "ltr","code": "en"}]},"bn": {"name": "Bangla","nativeName": "বাংলা","dir": "ltr","translations": [{"name": "English","nativeName": "English","dir": "ltr","code": "en"}]},"bs": {"name": "Bosnian","nativeName": "Bosnian","dir": "ltr","translations": [{"name": "English","nativeName": "English","dir": "ltr","code": "en"}]},"zh-Hans": {"name": "Chinese Simplified","nativeName": "中文 (简体)","dir": "ltr","translations": [{"name": "English","nativeName": "English","dir": "ltr","code": "en"}]}}
}

【Microsoft Azure 的1024种玩法】七十二.使用NodeJS手动编写调用Azure Cognitive Services Translator API代码获取其支持翻译的语言集相关推荐

  1. 【Microsoft Azure 的1024种玩法】十五.通过Web浏览器对Auzre VM 服务器运维管理

    [简介] Apache Guacamole是无客户端远程桌面网关.它支持标准协议,例如VNC,RDP和SSH.我们称其为无客户端,因为不需要插件或客户端软件.多亏了HTML5,在服务器上安装了鳄梨调味 ...

  2. 【Microsoft Azure 的1024种玩法】七十四.五分钟在Azure Virtual Machines中快速部署一套软件项目管理及自动构建工具

    [简介] Apache Maven由 Apache 软件基金会所提供的一个软件项目管理及自动构建工具,Maven 为开发者提供了一套完整的构建生命周期框架.开发团队几乎不用花多少时间就能够自动完成工程 ...

  3. 【Microsoft Azure 的1024种玩法】七十一.基于Azure Virtual Machines快速上手搭建Typecho博客系统

    [简介] Typecho 是基于 PHP5 构建的开源跨平台博客系统,Typecho开源跨平台博客系统相较于wordpress .hexo有一定的性能优势,是我们记录文章内容的最佳首选博客,那么本篇文 ...

  4. 【Microsoft Azure 的1024种玩法】二十六. 在Azure VM中手动部署Windows Admin Center管理平台

    [简介] Windows Admin Center是微软开发的一套可以部署在本地基于浏览器的GUI的工具集平台,其平台可用于管理Windows相关服务器和PC机器,我们可以利用Windows Admi ...

  5. 【Microsoft Azure 的1024种玩法】四十二. 通过Windows Admin Center快速创建Azure Virtual Machines

    [简介] Windows Admin Center是微软开发的一套可以部署在本地基于浏览器的GUI的工具集平台,其平台可用于管理Windows相关服务器和PC机器,我们可以利用Windows Admi ...

  6. 【Microsoft Azure 的1024种玩法】五十. 通过Azure文件共享将Azure File 挂载到本地机器实现文件实时共享

    [简介] Azure 文件是 Microsoft 推出的易用云文件系统. Azure 文件共享可以在 Windows 和 Windows Server 中无缝使用. 本文介绍如何通过Azure文件共享 ...

  7. 【Microsoft Azure 的1024种玩法】二十四.通过Azure Front Door 的 Web 应用程序防火墙来对 OWASP TOP 10 威胁进行防御

    [简介] 我们都知道像 SQL 注入.跨站点脚本攻击(XSS)之类的恶意攻击以及 OWASP 发现的十大威胁都可能会导致服务中断或数据丢失,让 Web 应用程序所有者受到巨大威胁.那么如何有效的解决O ...

  8. 【Microsoft Azure 的1024种玩法】六十.通过Azure Virtual Machines快速搭建个人Ghost博客系统

    [简介] Ghost 是一套基于Node.js 语言开发构建的开源博客系统,它的整体架构为前端管理系统基于Ember.js, 后端的模板引擎采用的handlebars, 数据库是基于MySQL的,本篇 ...

  9. 【Microsoft Azure 的1024种玩法】四十五.在Azure中快速创建Azure AD Domain Services

    [简介] Azure Active Directory (Azure AD) 是一种基于云的标识和访问管理服务. Azure Active Directory 可帮助相关企业访问内部资源,例如企业 I ...

最新文章

  1. OC中protocol、category和继承的区别
  2. this和self区别
  3. python双循环zip_Python如何同时进行两个循环
  4. 每日一笑 | 床上还是桌上,你总得选一样~
  5. 零基础学sql要多久_零基础小白如何迈出学习SQL的第一步?文科生学SQL的心得
  6. java 重力脚本_Java中非常简单的脚本解析器
  7. python对象之间的关系
  8. linux 下 ffmpeg 库怎么才可以调试
  9. php数据库数据分割,使用PHP将分隔的值文件导入数据库时??,...
  10. PowerDesigner 下载安装
  11. route -n 详解
  12. html水印生成pdf,如何在jsPDF中添加PDF生成水印?
  13. Nepire的校OJ入门题解—17蓝桥选拔篇(二)
  14. UVA 12304 计算几何+圆模板
  15. BZOJ 1189 [HNOI2007]紧急疏散evacuate 二分+最大流
  16. 学一点django基础
  17. 01.自我意识的觉醒
  18. Windows Azure 虚拟网络中虚拟机的网络隔离选项
  19. 我的2021秋招 | 互联网、银行、选调 经验分享
  20. 嵌入式文件系统损耗平衡算法

热门文章

  1. restart.sh
  2. 微服务调用失败的一种解决方案
  3. IP、TCP、UDP首部详解
  4. ubuntu下火狐浏览器无法播放视频解决方案(适用20.04及以上)
  5. PDF文件如何进行格式转换?
  6. Windows提示缺少msxml3.dll文件如何解决?
  7. wp8系统不行android,微软的WP系统之死,并不是因为iOS和Android太强
  8. buuctf · windows系统密码 · wp
  9. idea2019导入maven项目中的某些问题
  10. 站长说说之 seo中蜘蛛是否能抓住网站的动态页面