Yandex.Translator

NET library for Yandex.Translate web service (http://api.yandex.ru/translate), used for text translation.


Keywords
yandex, language, translate, translator
License
LGPL-2.1
Install
Install-Package Yandex.Translator -Version 2.0.0

Documentation

Yandex.Translator is a .NET library for Yandex.Translate web service (Yandex.Translate web service), used for text translation.

NuGet package : https://www.nuget.org/packages/Yandex.Translator


Support

This project needs your support for further developments ! Please consider donating.

  • Yandex.Money : 41001577953208

  • WebMoney (WMR) : R399275865890

Image


Initialization

Before you can make requests to the Yandex.Translate API, you need to setup it. The following information is required :

  1. APIKey which you can acquire from here - http://api.yandex.ru/key/form.xml?service=trnsl

  2. Data exchange format to use (XML/JSON).

Example (initialize API, using value of API key stored inside application configuration file):

IYandexTranslator translator = Yandex.Translator(api => api.ApiKey(ConfigurationManager.AppSettings["ApiKey"]).Format(ApiDataFormat.Json));


Supported set of operations:


Translations pairs

Description: Returns list of supported language pairs (translation directions), consisting of source and destination language codes (for example, "en-ru").

Documentation: http://api.yandex.ru/translate/doc/dg/reference/getLangs.xml

Code:

IYandexTranslator translator = ...

IEnumerable<ITranslationPair> translationPairs = translator.TranslationPairs();


Language detection

Description: Detects natural language of the provided text fragment.

Documentation: http://api.yandex.ru/translate/doc/dg/reference/detect.xml

IYandexTranslator translator = ...

string language = translator.Detect("This is English text");

Text translation

Description: Performs translation of provided text fragment from source to destination languages.

Documentation: http://api.yandex.ru/translate/doc/dg/reference/translate.xml

Code:

IYandexTranslator translator = ...

ITranslation translation = translator.Translate("ru", "To be translated to Russian");

ITranslation translation = translator.Translate("en-ru", "To be translated from English to Russian", "html");

ITranslation translation = translator.Translate(request => request.From("en").To("ru").Text("To be translated from English to Russian").Html());