Yandex.Translate
1.0.1
dotnet add package Yandex.Translate --version 1.0.1
NuGet\Install-Package Yandex.Translate -Version 1.0.1
<PackageReference Include="Yandex.Translate" Version="1.0.1" />
paket add Yandex.Translate --version 1.0.1
#r "nuget: Yandex.Translate, 1.0.1"
// Install Yandex.Translate as a Cake Addin #addin nuget:?package=Yandex.Translate&version=1.0.1 // Install Yandex.Translate as a Cake Tool #tool nuget:?package=Yandex.Translate&version=1.0.1
Yandex.Translate Client
This is a simple client for the Yandex.Translate service.
Core Features
All core features share the same client class TranslateClient
.
To start using it simply create a new instance of the class:
- At first, create configuration object (for now it contains API key property only)
- Then simply create
TranslateClient
instance.
var config = new TranslateClientConfiguration("YOUR_API_KEY");
var client = new TranslateClient(config);
Translation
To translate text you can use TranslateClient.TranslateAsync(text, sourceLang, targetLang, format = text)
method
which returns Translation
object that contains possible translations and some additional metadata
like source string, source and target language codes and format.
var translation = await client.TranslateAsync("Hellow World!", "en", "ru");
Console.WriteLine(translation.First()!) // Output: "Привет, мир!"
TranslateClient.TranslateAsync
Accepts the following arguments:
- Text to be translated (
string
); - Source language code (
string
); - Target language code (
string
); - Translate format, which specifies whether text to be translated is a plain text or HTML (
TextFormat
enum).
Language Detection
To detect language you can use TranslateClient.DetectLanguageAsync(text, hintLanguages)
method
which returns detected language code.
var detectedLanguage = await client.DetectLanguageAsync("Hello World!");
Console.WriteLine(detectedLanguage) // Output: "en"
DetectLanguageAsync
accepts the following parameters:
- Text which is used as reference for language detection (
string
); - Hint languages. When detecting language, hint language will be preferred (
IEnumerable<string>
).
Supported Languages
To get supported languages you can use the TranslateClient.GetSupportedLanguages(displayLanguageCode = "en")
method:
var supportedLanguagesData = await client.GetSupportedLanguages();
foreach(var language in supportedLanguagesData.Languages) {
Console.WriteLine(language.Code) // Output: "en", "ru", "pt"
Console.WriteLine(language.Name) // Output: "English", "Russian", "Protugeese".
}
foreach(var direction in supportedLanguagesData.Directions) {
Console.WriteLine(direction.SourceLanguage) // Output: "en", "en", "en"
Console.WriteLine(direction.TargetLanguage) // Output: "ru", "pt", "es"
}
GetSupportedLanguages
accepts displayLanguageCode
which specifies which language will be used to display language names.
The method returns SupportedLanguagesData
object which contains supported languages and supported directions.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Yandex.Translate:
Package | Downloads |
---|---|
Yandex.Translate.Extensions.DependencyInjection
Dependency Injection extensions for for the Yandex.Translate package. |
GitHub repositories
This package is not used by any popular GitHub repositories.