【问题标题】:How to use Google Translate API in .net core website?如何在 .net 核心网站中使用 Google Translate API?
【发布时间】:2021-03-30 10:12:59
【问题描述】:

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

【问题讨论】:

  • 你能得到任何帮助吗?

标签: asp.net-core .net-core google-translate google-translation-api


【解决方案1】:

例如,您可以编写如下代码来翻译句子:

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.

【讨论】:

  • 任何示例代码或博客包含逐步实现?
  • 我已经用我刚刚找到的一个例子更新了答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-27
  • 2023-04-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多