微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 .net 核心网站中使用 Google Translate API?

如何解决如何在 .net 核心网站中使用 Google Translate API?

如何在我的 .NET 核心应用程序中使用 Google Translate api?我试过基本的 html 和文本翻译都工作正常。现在我想将我的整个网站转换成多语言。我怎样才能做到这一点。作为参考,我正在使用 this link

解决方法

例如,您可以编写这样的代码来翻译一个句子:

var sentence = "This is some html text to <strong>translate</strong>!";
// Target language is french
string targetLanguage = "fr";
// Source language is automatically detected
string sourceLanguage = null; 
// We create the TranslationClient
var client = Google.Cloud.Translation.V2.TranslationClient.Create();
// We translate
var response = client.TranslateHtml(sentence,targetLanguage,sourceLanguage);
// Output
Console.WriteLine(response.TranslatedText);
// C&#39;est un texte html à <strong>traduire</strong> !

Code source

Official documentation on how to get started using the Google Translate API in .NET

.NET reference documentation for the Cloud Translation API.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。