TranslationProviderYandex
Namespace: Wisej.Ext.Translation
Assembly: Wisej.Ext.Translation (4.1.0.0)
Yandex translation provider.
- C#
- VB.NET
public class TranslationProviderYandex : TranslationProviderBase
Public Class TranslationProviderYandex
Inherits 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
TranslationProviderYandex()
Initializes a new instance of TranslationProviderYandex.
Properties
ClientSecret
String: The secret client-key or api-key for the provider.
Methods
Translate(text, from, to)
Invokes the translation service provider and returns the result of the request in an instance of the TranslationResult class.
| Parameter | Type | Description |
|---|---|---|
| text | String | The text to translate. |
| from | String | The source language code ("en", "de", ...), or null or empty to let the provider auto-detect the source language. |
| to | String | The 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);
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.
| Parameter | Type | Description |
|---|---|---|
| text | String | The text to translate. |
| from | String | The source language code ("en", "de", ...), or null or empty to let the provider auto-detect the source language. |
| to | String | The target language code ("en", "de", ...). |
| resultCallback | Action<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);
});