I have an application where a user can add clients in both Arabic and English, my use-case is simple:
- user fill-in the client first name and last name in Arabic
- behind the scene, I call my backend to get the equivalent of names in English
- English first name and last name will be filled automatically from the server response, user can edit them of course
For that, I am using 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"
}
}
So the main obstacle for me is how to get the equivalent name and not the translation of the text (names)
to illustrate that via an example using Google translate:
So this translates the Arabic name مراد to the Inend which is incorrect, In my case I want "Mourad".
I had a hard time searching for that since I don't know how to express this kind of translation. So My question is shortly: How to translate names based on their spelling and their meaning using Google Cloud Translation Service in C#?