Bitzsoft.Integrations.Translation.Aliyun 1.0.0

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

Bitzsoft.Integrations.Translation.Aliyun

阿里云机器翻译(alimt)实现包 -- 专业版 / 通用版 Translate 接口,POP RPC v1 HMAC-SHA1 签名,实现 ITranslationProvider 统一契约。

功能特性

  • 官方 API 直连:裸 HttpClient 直调 alimt REST API,零厂商 SDK 依赖
  • 专业版 / 通用版切换:ApiEdition 一键切换(专业版质量更好,通用版成本更低)
  • 场景化翻译:专业版支持 general / message / legal 等场景,法律文书推荐 legal
  • auto 源语言:SourceLanguage 留空或 auto 由阿里云自动检测
  • 限流退避重试:net8+ 标准韧性 handler(429/503/504 指数退避),次数与基准延迟可配
  • 请求审计:内置 RequestLogging 管道记录出站请求
  • 健康探测:CheckHealthAsync 以最小代价(单字符翻译)探测可用性

安装

dotnet add package Bitzsoft.Integrations.Translation.Aliyun
<PackageReference Include="Bitzsoft.Integrations.Translation.Aliyun" Version="1.0.0" />

配置

appsettings.json

{
  "Translation": {
    "Aliyun": {
      "AppId": "your-access-key-id",
      "AppSecret": "your-access-key-secret",
      "ApiEdition": "Professional",
      "Scene": "legal",
      "Region": "cn-hangzhou"
    }
  }
}
配置项 说明 必填 默认值
AppId 阿里云 AccessKey ID(继承统一 Options) 是 -
AppSecret 阿里云 AccessKey Secret(POP 签名用,脱敏落日志) 是 -
ApiEdition Professional(专业版 Translate)/ General(通用版) 否 Professional
Scene 翻译场景(专业版支持 general / message / legal 等) 否 general
Endpoint 服务端点 否 mt.cn-hangzhou.aliyuncs.com
BaseAddress 端点覆盖(优先于 Endpoint,含协议) 否 -
Region 地域 否 cn-hangzhou
Timeout HTTP 超时 否 30s
MaxRetryAttempts / RetryBaseDelay 限流退避重试次数 / 基准延迟 否 3 / 500ms
HttpClientName 命名 HttpClient 标识 否 AliyunTranslationProvider

注册服务

using Microsoft.Extensions.DependencyInjection;

// 从配置绑定(推荐)
builder.Services.AddBitzsoftAliyunTranslation(builder.Configuration);

// 或指定配置节
builder.Services.AddBitzsoftAliyunTranslation(builder.Configuration, "Translation:Aliyun");

// 或委托配置
builder.Services.AddBitzsoftAliyunTranslation(options =>
{
    options.AppId = "your-access-key-id";
    options.AppSecret = "your-access-key-secret";
    options.Scene = "legal";
});

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

使用示例

public class ContractTranslator(ITranslationProviderFactory factory)
{
    public async Task<string> TranslateAsync(string clause)
    {
        var provider = factory.GetProvider(TranslationProviderCode.Aliyun);

        var result = await provider.TranslateAsync(new TranslationTextRequest
        {
            Text = clause,
            SourceLanguage = "auto",
            TargetLanguage = "en",
            Format = TranslationTextFormat.Text
        });

        return result.IsSuccess ? result.Data!.TranslatedText : throw new InvalidOperationException(result.ErrorMessage);
    }
}

能力矩阵

能力 支持 说明
单文本翻译 ✅ 专业版 / 通用版
批量翻译 ✅ 逐条调用保持顺序(alimt 单请求单文本)
语言检测 ❌ 返回 NotSupported;auto 翻译时可自动检测但不回显语种
领域词汇表(Terms) ❌ 阿里云术语库需控制台绑定;请求内 Terms 被忽略
HTML 格式 ✅ Format = TranslationTextFormat.Html → FormatType=html
健康探测 ✅ 单字符翻译探测(产生最小计费字符)

已知限制:单次 SourceText 上限 5000 字符,超长文本由调用方分段。

错误码收敛

alimt 原始信号 统一错误码
InvalidAccessKeyId / SignatureDoesNotMatch / Unauthorized AuthenticationFailed
10010009 / 语向不支持 LanguageNotSupported
10010007 / InvalidParameter / 长度超限 InvalidArgument
10010002 / 10010008 / 流量 / QPS / Throttling RateLimited
10010003 / 10010004 / 10010005 / 额度 / 欠费 QuotaExceeded
网络异常 / DNS 解析失败 NetworkUnreachable
超时 Timeout

相关包

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.Aliyun:

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 58 10/21/2026