Translating text with GroupDocs.Translation SDK
Leave feedback
Although you can directly call the GroupDocs.Translation Cloud REST API to send text for translation and fetch translated text, there is a much easier way to implement translation functionality in your applications. We provide software development kits (SDKs) for all popular programming languages. They wrap up all routine operations such as establishing connections, sending API requests, and parsing responses into a few simple methods. It makes interaction with GroupDocs.Translation Cloud services much easier, allowing you to focus on business logic rather than technical details.
usingSystem.Collections.Generic;usingSystem.Diagnostics;usingSystem.Linq;usingSystem.Threading;usingGroupDocs.Translation.Cloud.Sdk.Api;usingGroupDocs.Translation.Cloud.Sdk.Client;usingGroupDocs.Translation.Cloud.Sdk.Client.Auth;usingGroupDocs.Translation.Cloud.Sdk.Extensions;usingGroupDocs.Translation.Cloud.Sdk.Model;usingHttpStatusCode=System.Net.HttpStatusCode;namespaceGroupDocs.Translation.Cloud.Sdk{publicclassTextTranslator{publicTextTranslator(){Configurationconfig=newConfiguration();/** Authorize your requests to GroupDocs.Translation Cloud */config.OAuthFlow=OAuthFlow.APPLICATION;config.OAuthClientId="YOU_CLIENT_ID";config.OAuthClientSecret="YOU_CLIENT_SECRET";/** Initialize GroupDocs.Translation API */config.BasePath="https://api.groupdocs.cloud/v2.0/translation";TranslationApiapiInstance=newTranslationApi(config);/** Specify translation parameters */stringtranslateFrom=newList<string>(){"Hello, world! I can read this text in my language."};stringsourceLanguage="en";vartargetLanguages=newList<string>(){"de"};varrequest=newTextRequest(sourceLanguage:sourceLanguage,targetLanguages:targetLanguages,texts:translateFrom);/** Send text to translation */StatusResponsetranslationStatus=apiInstance.TextPost(request);/** Wait for results from translation queue */if(translationStatus.Status.ToSystemHttpStatusCode()==HttpStatusCode.Accepted){while(true){varresult=apiInstance.TextRequestIdGet(statusResponse.Id);if(result.Status.ToSystemHttpStatusCode()==HttpStatusCode.OK){Console.WriteLine(result.Translations[toLang].First());break;}Thread.Sleep(1000);}}}}}
importtimeimportgroupdocs_translation_cloudfromgroupdocs_translation_cloudimportTextRequest,Formatapi=groupdocs_translation_cloud.api.TranslationApi()api.api_client.configuration.client_id="YOU_CLIENT_ID"api.api_client.configuration.client_secret="YOU_CLIENT_SECRET"text_request=TextRequest(source_language="en",target_languages=["es","fr","ru"],texts=["Hello World!","This is a test text"],origin="your_application_name",contains_markdown=False)response=api.text_post(text_request)ifresponse.status==202:whileTrue:status_response=api.text_request_id_get(response.id)ifstatus_response.status==200:forlanginstatus_response.translations:print(lang+": "+status_response.translations[lang][0])breaktime.sleep(2)