ForeverTools.Translate
1.0.0
dotnet add package ForeverTools.Translate --version 1.0.0
NuGet\Install-Package ForeverTools.Translate -Version 1.0.0
<PackageReference Include="ForeverTools.Translate" Version="1.0.0" />
<PackageVersion Include="ForeverTools.Translate" Version="1.0.0" />
<PackageReference Include="ForeverTools.Translate" />
paket add ForeverTools.Translate --version 1.0.0
#r "nuget: ForeverTools.Translate, 1.0.0"
#:package ForeverTools.Translate@1.0.0
#addin nuget:?package=ForeverTools.Translate&version=1.0.0
#tool nuget:?package=ForeverTools.Translate&version=1.0.0
ForeverTools.Translate
AI-powered translation for .NET using GPT-4, Claude, Llama and 400+ AI models. Translate text between 100+ languages with automatic language detection, batch translation, and context-aware results.
Features
- 100+ Languages: Translate between any language pair
- Auto Language Detection: Automatically detect source language
- Multiple AI Models: GPT-4, Claude, Llama, Gemini, Mistral, and more
- Batch Translation: Translate multiple texts efficiently
- Context-Aware: Provide context for more accurate translations
- Custom Glossaries: Ensure consistent terminology
- Multiple Styles: Natural, formal, casual, technical, and more
- Easy Integration: Simple API with dependency injection support
Getting Your API Key
This package uses the AI/ML API which provides access to 400+ AI models including GPT-4, Claude, Llama, and more.
- Sign up at aimlapi.com
- Get your API key from the dashboard
- Start translating!
Installation
dotnet add package ForeverTools.Translate
Quick Start
Basic Translation
using ForeverTools.Translate;
// Create client with your API key
var client = new TranslationClient("your-api-key");
// Translate to Spanish (auto-detect source language)
var spanish = await client.TranslateAsync("Hello, how are you?", "es");
// Output: "Hola, ¿cómo estás?"
// Translate to English
var english = await client.TranslateToEnglishAsync("Bonjour le monde");
// Output: "Hello world"
Using Environment Variables
// Set AIML_API_KEY or TRANSLATION_API_KEY environment variable
var client = TranslationClient.FromEnvironment();
Language Detection
var result = await client.DetectLanguageAsync("Bonjour, comment allez-vous?");
Console.WriteLine($"Language: {result.LanguageName}"); // French
Console.WriteLine($"Code: {result.LanguageCode}"); // fr
Console.WriteLine($"Confidence: {result.Confidence}"); // 0.98
Batch Translation
// Translate multiple texts at once
var texts = new[] { "Hello", "Goodbye", "Thank you" };
var results = await client.TranslateBatchAsync(texts, "es");
foreach (var result in results.Results)
{
Console.WriteLine($"{result.OriginalText} → {result.TranslatedText}");
}
// Hello → Hola
// Goodbye → Adiós
// Thank you → Gracias
Translate to Multiple Languages
// Translate one text to multiple languages simultaneously
var languages = new[] { "es", "fr", "de", "ja" };
var results = await client.TranslateToMultipleLanguagesAsync("Hello world", languages);
foreach (var result in results)
{
Console.WriteLine($"{result.TargetLanguage}: {result.TranslatedText}");
}
// es: Hola mundo
// fr: Bonjour le monde
// de: Hallo Welt
// ja: こんにちは世界
Translation Styles
// Formal (business documents)
var formal = await client.TranslateWithStyleAsync(
"Hey, what's up?",
"es",
TranslationStyle.Formal);
// "Buenos días, ¿cómo se encuentra?"
// Casual (conversational)
var casual = await client.TranslateWithStyleAsync(
"Greetings, how do you do?",
"es",
TranslationStyle.Casual);
// "¡Hola! ¿Qué tal?"
// Technical (preserve terminology)
var technical = await client.TranslateWithStyleAsync(
"The API returns a JSON response with pagination.",
"de",
TranslationStyle.Technical);
Available styles:
Natural- Fluent, natural-sounding translation (default)Formal- Professional, business-appropriateCasual- Friendly, conversationalTechnical- Preserves technical terminologyLiteral- Stays close to source structureCreative- More freedom for adaptation
Context-Aware Translation
// Provide context for more accurate translation
var translation = await client.TranslateWithContextAsync(
"Apple announced new products today.",
"es",
"This is a technology news article about the company Apple Inc.");
// "Apple anunció nuevos productos hoy." (not the fruit!)
Custom Glossaries
// Ensure consistent terminology
var glossary = new Dictionary<string, string>
{
["cloud"] = "la nube",
["server"] = "el servidor",
["API"] = "API" // Keep as-is
};
var translation = await client.TranslateWithGlossaryAsync(
"The cloud server exposes an API.",
"es",
glossary);
// "El servidor en la nube expone una API."
Using Different AI Models
// Use GPT-4 for highest quality
var options = new TranslationOptions
{
ApiKey = "your-api-key",
DefaultModel = TranslationModels.Gpt4o
};
var client = new TranslationClient(options);
// Or specify per-request
var request = new TranslationRequest
{
Text = "Hello world",
TargetLanguage = "ja",
Model = TranslationModels.Claude35Sonnet
};
var result = await client.TranslateWithDetailsAsync(request);
Available models include:
TranslationModels.Gpt4o- Best quality (default)TranslationModels.Gpt4oMini- Fast and affordableTranslationModels.Claude35Sonnet- Excellent for nuanced translationTranslationModels.Gemini15Pro- Google's latestTranslationModels.Llama3170B- Open source optionTranslationModels.Qwen72B- Excellent for Asian languages
Predefined Languages
// Use predefined language constants
using ForeverTools.Translate;
var spanish = Languages.Spanish; // es
var japanese = Languages.Japanese; // ja
var chinese = Languages.ChineseSimplified; // zh-CN
// Or use language codes directly
var result = await client.TranslateAsync("Hello", "es");
Dependency Injection
ASP.NET Core
// In Program.cs
builder.Services.AddForeverToolsTranslation("your-api-key");
// Or with configuration
builder.Services.AddForeverToolsTranslation(options =>
{
options.ApiKey = "your-api-key";
options.DefaultModel = TranslationModels.Gpt4oMini;
options.DefaultTargetLanguage = "es";
options.Style = TranslationStyle.Formal;
});
From Configuration
// appsettings.json
{
"Translation": {
"ApiKey": "your-api-key",
"DefaultModel": "gpt-4o",
"DefaultTargetLanguage": "en",
"Style": "Natural"
}
}
builder.Services.AddForeverToolsTranslation(builder.Configuration);
Using in Services
public class MyService
{
private readonly TranslationClient _translator;
public MyService(TranslationClient translator)
{
_translator = translator;
}
public async Task<string> TranslateContentAsync(string content, string language)
{
return await _translator.TranslateAsync(content, language);
}
}
Detailed Results
var result = await client.TranslateWithDetailsAsync(
"Bonjour le monde",
null, // Auto-detect source
"en");
Console.WriteLine($"Original: {result.OriginalText}");
Console.WriteLine($"Translated: {result.TranslatedText}");
Console.WriteLine($"Source Language: {result.SourceLanguage}");
Console.WriteLine($"Target Language: {result.TargetLanguage}");
Console.WriteLine($"Model Used: {result.Model}");
Console.WriteLine($"Language Detected: {result.WasLanguageDetected}");
Supported Languages
The package supports 50+ predefined languages including:
| Language | Code | Language | Code |
|---|---|---|---|
| English | en | Spanish | es |
| French | fr | German | de |
| Italian | it | Portuguese | pt |
| Russian | ru | Japanese | ja |
| Korean | ko | Chinese (Simplified) | zh-CN |
| Chinese (Traditional) | zh-TW | Arabic | ar |
| Hindi | hi | Vietnamese | vi |
| Thai | th | Turkish | tr |
| Dutch | nl | Polish | pl |
| Swedish | sv | Greek | el |
And many more! Any language can be used by passing its ISO 639-1 code.
Error Handling
try
{
var translation = await client.TranslateAsync("Hello", "es");
}
catch (ArgumentException ex)
{
Console.WriteLine($"Invalid input: {ex.Message}");
}
catch (HttpRequestException ex)
{
Console.WriteLine($"API error: {ex.Message}");
}
Best Practices
- Reuse the client: Create one
TranslationClientand reuse it - Use batch translation: For multiple texts, use
TranslateBatchAsync - Provide context: For ambiguous text, use
TranslateWithContextAsync - Choose the right model: Use GPT-4o for quality, GPT-4o-mini for speed
- Use glossaries: For consistent terminology across translations
Other ForeverTools Packages
Support
License
MIT License - see LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. 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 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- OpenAI (>= 2.1.0)
- System.Text.Json (>= 8.0.5)
-
net6.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- OpenAI (>= 2.1.0)
-
net8.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- OpenAI (>= 2.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 161 | 12/13/2025 |