Use Google Cloud Translation with C#
- Follow the guide to set up an account.
- Download the private key as JSON and save it under folder Assets (e.g. API Project-xxxxxxx.json). IMPORTANT: set its Build Action as Embedded resource.
- Install NuGet package Google.Cloud.Translation.V2.
- Create TranslationClient
TranslationClient _tc;
GoogleCredential gc = GoogleCredential.FromStream(Utility.GetStreamFromResourceFile("API Project-xxxxxxx.json", GetType()));
_tc = TranslationClient.Create(gc);
You can traslate like the following example that translates "Text to be translated" from German to English:
string sTranslatedText = _tc.TranslateText("Text to be translated", "en", "de").TranslatedText;