AzureAICommunity.Agent.Middleware.LanguageTranslationMiddleware 1.0.0

dotnet add package AzureAICommunity.Agent.Middleware.LanguageTranslationMiddleware --version 1.0.0
                    
NuGet\Install-Package AzureAICommunity.Agent.Middleware.LanguageTranslationMiddleware -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AzureAICommunity.Agent.Middleware.LanguageTranslationMiddleware" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AzureAICommunity.Agent.Middleware.LanguageTranslationMiddleware" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="AzureAICommunity.Agent.Middleware.LanguageTranslationMiddleware" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AzureAICommunity.Agent.Middleware.LanguageTranslationMiddleware --version 1.0.0
                    
#r "nuget: AzureAICommunity.Agent.Middleware.LanguageTranslationMiddleware, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AzureAICommunity.Agent.Middleware.LanguageTranslationMiddleware@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AzureAICommunity.Agent.Middleware.LanguageTranslationMiddleware&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=AzureAICommunity.Agent.Middleware.LanguageTranslationMiddleware&version=1.0.0
                    
Install as a Cake Tool

<div align="center">

🌐 AzureAICommunity – Language Translation Middleware (.NET)

Automatic language detection, translation, and response back-translation middleware for AI agent applications built on Microsoft.Extensions.AI.

NuGet License GitHub Repo GitHub Follow YouTube Channel YouTube Subscribers LinkedIn

**Your agent always

</div>


Overview

AzureAICommunity.Agent.Middleware.LanguageTranslationMiddleware is a plug-and-play translation layer for Microsoft.Extensions.AI chat pipelines. It automatically detects the user's language, translates incoming messages to the agent's target language, and back-translates the response β€” using Azure AI Translator with an optional LLM agent as fallback.


✨ Features

Feature
πŸ” Language detection β€” automatically detect the user's language with configurable confidence threshold
πŸ”„ Round-trip translation β€” translate incoming messages and back-translate agent responses
☁️ Azure Translator β€” production-grade speed and accuracy with 100+ languages
πŸ€– LLM fallback β€” silently falls back to LLM translation when Azure is unavailable
πŸ”§ Builder pattern β€” fluent CreateBuilder() API for easy composition
🌊 Streaming support β€” works with both standard and streaming IChatClient calls
πŸ”Œ Drop-in middleware β€” integrates directly into any Microsoft.Extensions.AI pipeline

πŸ“¦ Installation

dotnet add package AzureAICommunity.Agent.Middleware.LanguageTranslationMiddleware

πŸš€ Quick Start

using AzureAICommunity.Agent.Middleware.LanguageTranslationMiddleware;
using Microsoft.Extensions.AI;
using OllamaSharp;

IChatClient ollamaClient = new OllamaApiClient(new Uri("http://localhost:11434/"), "llama3.2");

// LLM-only translation (no Azure credentials required)
var client = ollamaClient
    .AsBuilder()
    .Use(inner => LanguageTranslationMiddleware
        .CreateBuilder()
        .WithTargetLanguage("en")
        .WithLLMFallback(ollamaClient)
        .Build(inner))
    .Build();

var messages = new[] { new ChatMessage(ChatRole.User, "Wie heißt die Hauptstadt von Frankreich?") };
var response = await client.GetResponseAsync(messages);
Console.WriteLine(response.Messages[0].Text); // Reply back-translated to German

βš™οΈ Configuration

Parameter Method Default Description
targetLanguage WithTargetLanguage(string) "en" ISO 639-1 code of the language the agent reasons in
minConfidence WithMinConfidence(float) 0.8 Minimum detection confidence to apply translation
azureConfig WithAzureTranslator(config) null Azure Translator credentials (optional)
llmClient WithLLMFallback(client) null LLM client used as translation fallback or primary service

πŸ§‘β€πŸ’» Usage

var azureConfig = new AzureTranslatorConfig(
    Key:    Environment.GetEnvironmentVariable("AZURE_TRANSLATOR_KEY")!,
    Region: Environment.GetEnvironmentVariable("AZURE_TRANSLATOR_REGION")!
);

var client = ollamaClient
    .AsBuilder()
    .Use(inner => LanguageTranslationMiddleware
        .CreateBuilder()
        .WithAzureTranslator(azureConfig)
        .WithLLMFallback(ollamaClient)
        .WithTargetLanguage("en")
        .WithMinConfidence(0.8f)
        .Build(inner))
    .Build();

Option 2 β€” LLM Only

var client = ollamaClient
    .AsBuilder()
    .Use(inner => LanguageTranslationMiddleware
        .CreateBuilder()
        .WithLLMFallback(ollamaClient)
        .WithTargetLanguage("en")
        .Build(inner))
    .Build();

Option 3 β€” Direct Construction

var azureService  = new AzureTranslationService(azureConfig);
var llmService    = new LLMTranslationService(ollamaClient);

var middleware = new LanguageTranslationMiddleware(
    inner:           ollamaClient,
    primaryService:  azureService,
    targetLanguage:  "en",
    minConfidence:   0.8f,
    fallbackService: llmService);

πŸ”„ How It Works

User Message (any language)
        β”‚
        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   LanguageTranslationMiddleware β”‚
β”‚  1. Detect language             β”‚
β”‚  2. Translate β†’ target lang     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
               β–Ό
       Inner IChatClient
       (reasons in target lang)
               β”‚
               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   LanguageTranslationMiddleware β”‚
β”‚  3. Back-translate response     β”‚
β”‚     β†’ user's original language  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
               β–Ό
  Response (user's language)

🀝 Contributing

Contributions are welcome! Please open an issue to discuss what you'd like to change before submitting a pull request.

πŸ“ Repository: https://github.com/rvinothrajendran/AgentFramework

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/my-feature)
  3. Commit your changes (git commit -m 'Add my feature')
  4. Push to the branch (git push origin feature/my-feature)
  5. Open a Pull Request

πŸ‘€ Author

Built and maintained by Vinoth Rajendran.


πŸ“„ License

MIT Β© 2026 Vinoth Rajendran – AzureAICommunity

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 170 4/20/2026