问题描述
我有一个应用程序,用户可以在其中添加阿拉伯语和英语客户端,我的用例很简单:
- 用户用阿拉伯语填写客户的名字和姓氏
- 在幕后,我打电话给我的后端以获取等效的英文名称
- 服务器响应中会自动填写英文名字和姓氏,用户当然可以编辑它们
为此,我使用了 Google Cloud Translation API
using System;
using System.Threading.Tasks;
using Google.Apis.Auth.OAuth2;
using Google.Cloud.Translation.V2;
class Program
{
static async Task Main(string[] args)
{
var jsonPath = "C:/gcloud/key.json";
var credential = GoogleCredential.FromFile(jsonPath);
var client = TranslationClient.Create(credential);
var text = "مراد"; // arabic name that is spelled "Mourad"
var response = client.TranslateText(text,LanguageCodes.English,LanguageCodes.Arabic,TranslationModel.ServiceDefault);
Console.WriteLine(response.TranslatedText);
// current output "Intend"
// expected output "Mourad"
}
}
所以我的主要障碍是如何获得等效名称而不是文本(名称)的翻译
通过一个使用谷歌翻译的例子来说明:
因此,这将阿拉伯名称 مراد 翻译为 Inend,这是不正确的,就我而言,我想要“Mourad”。
我很难找到它,因为我不知道如何表达这种翻译。 所以我的问题很简单:如何使用 C# 中的 Google Cloud Translation Service 根据名称的拼写和含义翻译名称?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)