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
Initialization
Before you can make requests to the Yandex.Translate API, you need to setup it. The following information is required :
-
APIKey which you can acquire from here - https://api.yandex.ru/key/form.xml?service=trnsl
-
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: https://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: https://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: https://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());