Simple library in .net standard 2.0 to translate text using the Azure cognitive services translator (free up to 2M characters per month)
PromatTranslations is available from: NuGet PromatTranslations
// Initialize the PromatTranslator with your Azure API Key
PromatTranslator.ConfigureKey("YOUR_AZURE_TRANSLATOR_API_KEY");
// Optionally configure the region of the azure "Translator" resource, default assumes "global".
PromatTranslator.ConfigureRegionPrefix("westeurope"); OR
// Initialize with an IConfiguration (The configuration must define a key "AzureApiKey")
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("config.json")
.Build();
PromatTranslator.Configure(configuration); // Choose the original language (Spanish by default)
PromatTranslator.ConfigureLanguageFrom(Languages.Español); // Choose the base millis (200 by default).
// The retry timeout will be: BaseMillisecondsForTooManyRequestRetry * retryNumber + accumulatedDelay
PromatTranslator.ConfigureBaseMillisecondsForTooManyRequestRetry(200); // Get the translated text
var translated = await PromatTranslator.TranslateAsync("Hola Mundo", Languages.Ingles);using System;
using System.Threading.Tasks;
using Promat.Translations;
using Promat.Translations.Constants;
namespace ConsoleApp1
{
class Program
{
static async Task Main(string[] args)
{
// Initialize the PromatTranslator with your Azure API Key
PromatTranslator.ConfigureKey("YOUR_AZURE_TRANSLATOR_API_KEY");
// Get the translated text
Console.WriteLine(await PromatTranslator.TranslateAsync("Hola Mundo", Languages.Ingles));
Console.Read();
}
}
}