Bitzsoft.Integrations.Translation.All 1.0.0

dotnet add package Bitzsoft.Integrations.Translation.All --version 1.0.0
                    
NuGet\Install-Package Bitzsoft.Integrations.Translation.All -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="Bitzsoft.Integrations.Translation.All" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bitzsoft.Integrations.Translation.All" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Bitzsoft.Integrations.Translation.All" />
                    
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 Bitzsoft.Integrations.Translation.All --version 1.0.0
                    
#r "nuget: Bitzsoft.Integrations.Translation.All, 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 Bitzsoft.Integrations.Translation.All@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=Bitzsoft.Integrations.Translation.All&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Bitzsoft.Integrations.Translation.All&version=1.0.0
                    
Install as a Cake Tool

Bitzsoft.Integrations.Translation.All

翻译服务聚合包 -- 一次注册按配置自动装配全部翻译供应商:

编码 供应商 类型 能力亮点
aliyun 阿里云机器翻译(alimt 专业版 / 通用版) 传统机翻 legal 等场景化、auto 源语言
baidu 百度翻译开放平台 传统机翻 成本最低、多段对齐
tencent 腾讯云机器翻译 TMT 传统机翻 原生批量、独立语言检测
youdao 有道智云翻译 传统机翻 vocabId 术语词表、领域化翻译
deepl DeepL API(Pro / Free) 传统机翻 欧洲语系质量、glossary / context 术语、额度探测
google Google Cloud Translation v2(官方计费) 传统机翻 原生批量、检测含置信度
tongyi 通义翻译 Qwen-MT(百炼) AI 翻译 原生术语干预 terms、domains、接入最轻
baidu-ai 百度大模型文本翻译 AI 翻译 翻译指令(风格 / 术语注入)、控制台术语库干预、检测语种回显
volcengine 火山引擎机器翻译大模型(豆包) AI 翻译 原生批量 ≤16 条、术语直传 glossary_list、检测语种回显
openai OpenAI 兼容网关(OpenAI / GLM / DeepSeek / Kimi / Qwen) AI 翻译 法律文书级提示词、分段回拼、JSON 回退(net8+)
anthropic Anthropic Claude AI 翻译 复用既有 AI.Anthropic 适配器(net8+)

net5.0 资产仅含传统机翻与裸 HTTP AI 翻译(Tongyi / 百度大模型 / 火山引擎);OpenAI / Anthropic 依赖 Microsoft.Extensions.AI,仅在 net8+ 可用。

安装

dotnet add package Bitzsoft.Integrations.Translation.All

配置样例:多供应商并存(appsettings.json)

{
  "Translation": {
    "Aliyun": {
      "AppId": "your-access-key-id",
      "AppSecret": "your-access-key-secret",
      "ApiEdition": "Professional",
      "Scene": "legal"
    },
    "Baidu": {
      "AppId": "your-baidu-appid",
      "AppSecret": "your-baidu-secret"
    },
    "DeepL": {
      "ApiKey": "your-deepl-auth-key",
      "Plan": "Pro"
    },
    "Google": {
      "ApiKey": "your-google-api-key"
    },
    "Tencent": {
      "AppId": "your-secret-id",
      "AppSecret": "your-secret-key"
    },
    "Tongyi": {
      "ApiKey": "sk-your-dashscope-key",
      "Model": "qwen-mt-plus",
      "DefaultDomains": "The text is from legal contract domain."
    },
    "BaiduAi": {
      "AppId": "your-baidu-appid",
      "ApiKey": "your-baidu-api-key",
      "DefaultReference": "使用正式法律文书风格翻译"
    },
    "Volcengine": {
      "ApiKey": "your-volcengine-api-key",
      "GlossaryTableName": "legal-terms"
    },
    "OpenAI": {
      "ClientName": "translation",
      "ModelId": "glm-4.6",
      "DefaultDomainHint": "法律合同"
    }
  }
}

只有出现在配置里的供应商才会注册;AI 网关(OpenAI / Anthropic)还需宿主另行 AddBitzChatClient(见对应包 README)。

注册服务

using Microsoft.Extensions.DependencyInjection;

builder.Services.AddBitzsoftTranslationAll(builder.Configuration);

按语言 / 用途路由

public class TranslationRouter(ITranslationProviderFactory factory)
{
    // 用途 → 供应商:法律文书走术语强约束的通义,站内消息走阿里云,批量外发走 Google
    private static readonly IReadOnlyDictionary<string, string> RouteByUsage = new Dictionary<string, string>
    {
        ["legal"] = TranslationProviderCode.Tongyi,    // 原生术语干预
        ["message"] = TranslationProviderCode.Aliyun,  // 场景化、低成本
        ["batch"] = TranslationProviderCode.Google,    // 原生批量 + 检测
        ["europe"] = TranslationProviderCode.DeepL,    // 欧洲语系质量
    };

    public async Task<string> TranslateAsync(string usage, string text, string targetLanguage)
    {
        var provider = factory.GetProvider(RouteByUsage[usage]);

        var result = await provider.TranslateAsync(new TranslationTextRequest
        {
            Text = text,
            SourceLanguage = "auto",
            TargetLanguage = targetLanguage,
            Terms = usage == "legal"
                ? new[] { new TranslationTerm("force majeure", "不可抗力") }
                : null,
        });

        if (result.IsSuccess)
            return result.Data!.TranslatedText;

        // 统一错误码驱动降级:配额 / 限流时回落到低成本通道
        if (result.ErrorCode is TranslationErrors.QuotaExceeded or TranslationErrors.RateLimited)
        {
            var fallback = await factory.GetProvider(TranslationProviderCode.Baidu)
                .TranslateAsync(new TranslationTextRequest { Text = text, TargetLanguage = targetLanguage });
            if (fallback.IsSuccess)
                return fallback.Data!.TranslatedText;
        }

        throw new InvalidOperationException($"{result.ErrorCode}: {result.ErrorMessage}");
    }
}

健康巡检

foreach (var code in factory.GetRegisteredCodes())
{
    var health = await factory.GetProvider(code).CheckHealthAsync();
    logger.LogInformation("翻译供应商 {Code} 状态 {Status}({Elapsed}ms)", code, health.Status, health.ElapsedMilliseconds);
}

相关包

  • Bitzsoft.Integrations.Translation.Abstractions -- 抽象层契约
  • 各供应商独立子包(Translation.Aliyun / .Baidu / .Tencent / .Youdao / .DeepL / .Google / .AI.Tongyi / .AI.Baidu / .AI.Volcengine / .AI.OpenAI / .AI.Anthropic)-- 按需精简引用
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  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 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 60 10/21/2026