Bitzsoft.Integrations.Translation.Google 1.0.0

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

Bitzsoft.Integrations.Translation.Google

Google Cloud Translation v2 官方 API 实现包(非免费网关,需启用 Cloud Translation API 并绑定结算账号)-- q 数组原生批量、/detect 检测含置信度、/languages 健康探测,实现 ITranslationProvider 统一契约。

功能特性

  • 官方计费 API:API Key 鉴权直连 translation.googleapis.com,替代不可运营的免费网关
  • 原生批量:q 数组单请求多文本,超 128 条自动分片,结果顺序一致
  • 语言检测:/detect 独立接口,返回语言、置信度(confidence)与可靠性(isReliable)
  • auto 源语言:source 省略时自动检测并逐条回显 detectedSourceLanguage
  • HTML 保留:Format = Html 时传 format=html,保留标签结构只翻译文本节点
  • 限流退避重试:net8+ 标准韧性 handler(429/503/504 指数退避),次数与基准延迟可配
  • 请求审计:内置 RequestLogging 管道记录出站请求
  • 健康探测:CheckHealthAsync 走支持语言列表(不计费字符)

安装

dotnet add package Bitzsoft.Integrations.Translation.Google

配置

appsettings.json

{
  "Translation": {
    "Google": {
      "ApiKey": "your-google-api-key",
      "Model": "nmt"
    }
  }
}
配置项 说明 必填 默认值
ApiKey Google Cloud API Key(继承统一 Options) 是 -
Endpoint v2 端点 否 https://translation.googleapis.com/language/translate/v2
BaseAddress 端点覆盖(优先于 Endpoint) 否 -
Model 翻译模型(nmt / base) 否 nmt
Timeout HTTP 超时 否 30s
MaxRetryAttempts / RetryBaseDelay 限流退避重试次数 / 基准延迟 否 3 / 500ms
HttpClientName 命名 HttpClient 标识 否 GoogleTranslationProvider

注册服务

builder.Services.AddBitzsoftGoogleTranslation(builder.Configuration);
// 或委托配置
builder.Services.AddBitzsoftGoogleTranslation(options =>
{
    options.ApiKey = "your-google-api-key";
});

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

使用示例

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

// 批量(原生 q 数组,超 128 条自动分片)
var batch = await provider.TranslateBatchAsync(new TranslationBatchRequest
{
    Texts = new[] { "第一条", "第二条" },
    SourceLanguage = "auto",
    TargetLanguage = "en"
});

// 检测(含置信度)
var detected = await provider.DetectLanguageAsync(new TranslationDetectRequest { Text = "Hello" });
// detected.Data.Language == "en",Confidence / IsReliable 可用

能力矩阵

能力 支持 说明
单文本翻译 ✅ v2 translate
批量翻译 ✅ q 数组原生批量,超 128 条自动分片
语言检测 ✅ /detect 独立接口,含置信度
领域词汇表(Terms) ❌ v2 Basic 不支持请求级术语;AutoML 词典在控制台维护
HTML 格式 ✅ format=html
健康探测 ✅ /languages 语言列表(不计费字符)

错误码收敛

Google 信号 统一错误码
403 + API_KEY_INVALID / PERMISSION_DENIED AccessDenied
403 + DAILY_LIMIT_EXCEEDED / limit QuotaExceeded
400 + message 含 language / target LanguageNotSupported
400(参数无效) InvalidArgument
429(USER_RATE_LIMIT_EXCEEDED) RateLimited
网络异常 / 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.Google:

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