Skip to main content

TranslationResult

Namespace: Wisej.Ext.Translation

Assembly: Wisej.Ext.Translation (4.1.0.0)

Represents the result of a translation request.

public class TranslationResult

Constructors​

Instance member TranslationResult(originalText, translatedText, from, to, errorCode, errorMessage)​

Constructs a new instance of TranslationResult.

NameTypeDescription
originalTextStringThe original text.
translatedTextStringThe translated text, or null if an error occurred.
fromStringThe language of the original text.
toStringThe language of the translated text.
errorCodeInt32The error code returned by the translation service, or -1 if the service returned an error message without an error code. Zero if the request was successful.
errorMessageStringThe error message returned by the translation service, or null if the request was successful.

Instances are normally created by a TranslationProviderBase implementation and returned by Translate.

Example:

// Successful translation.
var ok = new TranslationResult("Hello", "Hallo", "en", "de", 0, null);

// Failed translation.
var failed = new TranslationResult("Hello", null, "en", "de", 401, "API key is invalid");

foreach (var result in new[] { ok, failed })
{
if (result.ErrorCode == 0)
Console.WriteLine($"{result.OriginalText} -> {result.TranslatedText}");
else
Console.WriteLine($"Error {result.ErrorCode}: {result.ErrorMessage}");
}

Properties​

Instance member ErrorCode​

Int32: The error code returned by the translation service, or -1 if the service returned an error message without an error code. Zero if the request was successful.

Instance member ErrorMessage​

String: The error message returned by the translation service, or null if the request was successful.

Instance member OriginalLanguage​

String: Returns the language of the original text.

Instance member OriginalText​

String: The original text.

Instance member TargetLanguage​

String: Returns the language of the translated text.

Instance member TranslatedText​

String: The translated text, or null if an error occurred.