Bitzsoft.Integrations.Translation.Baidu 1.0.0

dotnet add package Bitzsoft.Integrations.Translation.Baidu --version 1.0.0
                    
NuGet\Install-Package Bitzsoft.Integrations.Translation.Baidu -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.Baidu" 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.Baidu" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Bitzsoft.Integrations.Translation.Baidu" />
                    
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.Baidu --version 1.0.0
                    
#r "nuget: Bitzsoft.Integrations.Translation.Baidu, 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.Baidu@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.Baidu&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Bitzsoft.Integrations.Translation.Baidu&version=1.0.0
                    
Install as a Cake Tool

Bitzsoft.Integrations.Translation.Baidu

百度翻译开放平台实现包 -- 通用翻译 API(AppId + 密钥 MD5 签名),实现 ITranslationProvider 统一契约。

功能特性

  • 官方 API 直连:裸 HttpClient 直调通用翻译端点,零厂商 SDK 依赖
  • MD5 请求签名:sign = MD5(appid + q + salt + 密钥),q 取 UTF-8 原文不转义
  • auto 源语言:SourceLanguage 留空或 auto 自动检测,检测语种在结果中回显(统一编码)
  • 多段对齐:原文含换行时按百度 trans_result 多段结构回拼
  • 限流退避重试:net8+ 标准韧性 handler(429/503/504 指数退避),次数与基准延迟可配
  • 请求审计:内置 RequestLogging 管道记录出站请求
  • 健康探测:CheckHealthAsync 以最小代价(单字符翻译)探测可用性

安装

dotnet add package Bitzsoft.Integrations.Translation.Baidu

配置

appsettings.json

{
  "Translation": {
    "Baidu": {
      "AppId": "your-baidu-appid",
      "AppSecret": "your-baidu-secret"
    }
  }
}
配置项 说明 必填 默认值
AppId 百度翻译开放平台 APPID(继承统一 Options) 是 -
AppSecret 百度密钥(签名用,脱敏落日志) 是 -
Endpoint 通用翻译 API 端点 否 https://api.fanyi.baidu.com/api/trans/vip/translate
BaseAddress 端点覆盖(优先于 Endpoint) 否 -
Timeout HTTP 超时 否 30s
MaxRetryAttempts / RetryBaseDelay 限流退避重试次数 / 基准延迟 否 3 / 500ms
HttpClientName 命名 HttpClient 标识 否 BaiduTranslationProvider

注册服务

builder.Services.AddBitzsoftBaiduTranslation(builder.Configuration);
// 或委托配置
builder.Services.AddBitzsoftBaiduTranslation(options =>
{
    options.AppId = "your-baidu-appid";
    options.AppSecret = "your-baidu-secret";
});

注册后 ITranslationProviderFactory 可按编码 baidu 解析。

使用示例

var provider = factory.GetProvider(TranslationProviderCode.Baidu);

var result = await provider.TranslateAsync(new TranslationTextRequest
{
    Text = "不可抗力条款",
    TargetLanguage = "en"
});

能力矩阵

能力 支持 说明
单文本翻译 ✅ 通用翻译 API
批量翻译 ✅ 逐条调用保持顺序(标准版 QPS=1)
语言检测 ❌ 返回 NotSupported;auto 翻译时回显检测语种
领域词汇表(Terms) ❌ 百度术语库在控制台维护;请求内 Terms 被忽略
HTML 格式 ❌ 通用翻译 API 不保留标签结构
健康探测 ✅ 单字符翻译探测(产生最小计费字符)

已知限制:单次 q 上限 6000 字节(UTF-8)。

错误码收敛

百度原始错误码 统一错误码
52001(超时) Timeout
52003 / 54001(授权 / 签名失败) AuthenticationFailed
54000(参数缺失) InvalidArgument
54003 / 54005 / 90107(QPS 超限) RateLimited
54004(余额不足) QuotaExceeded
58001(语向不支持) LanguageNotSupported
58002 / 52002(系统错误 / 服务关闭) OperationFailed
网络异常 / DNS 解析失败 NetworkUnreachable

相关包

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 (1)

Showing the top 1 NuGet packages that depend on Bitzsoft.Integrations.Translation.Baidu:

Package Downloads
Bitzsoft.Integrations.Translation.All

翻译服务聚合包 — 传统机翻(阿里云 / 百度 / 腾讯云 / 有道 / DeepL / Google 官方)+ AI 翻译(通义 Qwen-MT / 百度大模型 / 火山引擎大模型,OpenAI 兼容 / Anthropic net8+),配置存在性驱动注册

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 57 10/21/2026