Skip to main content

TranslationProviderYandex

Namespace: Wisej.Ext.Translation

Assembly: Wisej.Ext.Translation (4.1.0.0)

Yandex translation provider.

public class TranslationProviderYandex : TranslationProviderBase

This is the default provider used by the Translation component. It requires only an API key, set through ClientSecret (or ClientSecret). See https://tech.yandex.com/translate/.

Constructors​

Instance member TranslationProviderYandex()​

Initializes a new instance of TranslationProviderYandex.

Properties​

Instance member ClientSecret​

String: The secret client-key or api-key for the provider.

Methods​

Instance member Translate(text, from, to)​

Invokes the translation service provider and returns the result of the request in an instance of the TranslationResult class.

ParameterTypeDescription
textStringThe text to translate.
fromStringThe source language code ("en", "de", ...), or null or empty to let the provider auto-detect the source language.
toStringThe target language code ("en", "de", ...).

Returns: TranslationResult. A TranslationResult containing the translated text or, if the request failed, the error code and message.

The request is sent synchronously to the Yandex Translate API. Exceptions (e.g. network errors) are caught and returned as a TranslationResult whose ErrorCode is the exception's HResult.

Example:

var yandex = new TranslationProviderYandex { ClientSecret = "<your-yandex-api-key>" };

TranslationResult result = yandex.Translate("Buongiorno", null, "en");

if (result.ErrorCode == 0)
AlertBox.Show(result.TranslatedText);
else
AlertBox.Show(result.ErrorMessage, MessageBoxIcon.Error);

Instance member TranslateAsync(text, from, to, resultCallback)​

Invokes the translation service provider asynchronously and returns the result of the request in an instance of the TranslationResult class.

ParameterTypeDescription
textStringThe text to translate.
fromStringThe source language code ("en", "de", ...), or null or empty to let the provider auto-detect the source language.
toStringThe target language code ("en", "de", ...).
resultCallbackAction<TranslationResult>Callback method that will receive the TranslationResult when ready.

The request runs in a background task started with StartTask. Call Application.Update(this) in the callback to push UI changes to the browser.

Example:

var yandex = new TranslationProviderYandex { ClientSecret = "<your-yandex-api-key>" };

yandex.TranslateAsync("Buongiorno", "it", "en", result =>
{
label1.Text = result.TranslatedText ?? result.ErrorMessage;
Application.Update(this);
});