跳到正文
cccskills
免费在 GitHub 公开中文介绍

azure-ai-translation-text-py

在Python应用中接入Azure AI Translator,实现多语言翻译、语言检测、文字体系转换、词典查询和用例获取,并提供异步请求示例。

原文查看原文说明

Azure AI Text Translation SDK for real-time text translation, transliteration, language detection, and dictionary lookup. Use for translating text content in applications.

集成工具Azure

实测评分 未实测

查看安装方法

适用场景

  • 为Python应用添加多语言翻译
  • 检测输入文本的语言
  • 转换不同文字体系
  • 查询译词和用例

中文介绍

功能

本技能指导你在Python应用中集成Azure AI Translator文本功能。内容包括将一段或多段文本翻译成多种语言、检测源语言,以及在不同文字体系之间转换文本。还可以查询词典中的其他译法和释义、获取用法示例、识别句子边界,并对应原文和译文中的词语。文档也提供异步客户端示例。

适用场景

当你要为Python应用添加多语言文本功能、在翻译前识别用户输入的语言,或向用户展示某个词的其他译法和例句时,可以使用本技能。示例还涉及HTML文本和在一次请求中批量处理多段文本。

使用示例

  • “请为这个Python应用添加英语和日语翻译功能。”
  • “请编写检测输入语言并查询词典译法和用例的代码。”

注意事项

需要安装azure-ai-translation-text并配置Azure身份验证。示例使用带区域的API密钥或自定义终结点,也包含Entra ID身份验证方式。翻译、文字转换和词典功能支持的语言可能不同,使用前应通过语言列表功能核对。待翻译文本会发送到配置的Azure服务;传输敏感内容前应取得授权,并避免在日志中记录敏感信息。还应根据所用版本核对SDK调用方式和服务限制。

本介绍由 AI(OpenAI Codex)根据公开的 SKILL.md 撰写。准确的规格请查看下方原文。

文档检查

AI 根据 SKILL.md 的内容检查了需要注意的操作和使用前提。评分只依据实际运行的结果(实测对比)。

安全性发送数据、删除文件、执行命令等是否有说明
A良好资料说明文本会发送至Azure,并要求敏感内容先获授权且日志脱敏。
安装难易度所需工具和 API 密钥是否少且有说明
B部分不足需要安装SDK并配置Azure凭据、区域或终结点。

不计入评分。 由 AI(OpenAI Codex)于 2026年10月24日 评估。仅供参考,安装前请同时查看原文。

如果您认为评估有误,请申请复核

请写明哪一项有误以及原因。无需登录。我们会对照 SKILL.md 重新评估,并在此处更新结果。

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

包含的文件(1)

  • SKILL.md7.9 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Azure AI Text Translation SDK for Python

Client library for Azure AI Translator text translation service for real-time text translation, transliteration, and language operations.

Installation

pip install azure-ai-translation-text

Environment Variables

AZURE_TRANSLATOR_KEY=<your-api-key>
AZURE_TRANSLATOR_REGION=<your-region>  # e.g., eastus, westus2
# Or use custom endpoint
AZURE_TRANSLATOR_ENDPOINT=https://<resource>.cognitiveservices.azure.com

Authentication

API Key with Region

import os
from azure.ai.translation.text import TextTranslationClient
from azure.core.credentials import AzureKeyCredential

key = os.environ["AZURE_TRANSLATOR_KEY"]
region = os.environ["AZURE_TRANSLATOR_REGION"]

# Create credential with region
credential = AzureKeyCredential(key)
client = TextTranslationClient(credential=credential, region=region)

API Key with Custom Endpoint

endpoint = os.environ["AZURE_TRANSLATOR_ENDPOINT"]

client = TextTranslationClient(
    credential=AzureKeyCredential(key),
    endpoint=endpoint
)

Entra ID (Recommended)

from azure.ai.translation.text import TextTranslationClient
from azure.identity import DefaultAzureCredential

client = TextTranslationClient(
    credential=DefaultAzureCredential(),
    endpoint=os.environ["AZURE_TRANSLATOR_ENDPOINT"]
)

Basic Translation

# Translate to a single language
result = client.translate(
    body=["Hello, how are you?", "Welcome to Azure!"],
    to=["es"]  # Spanish
)

for item in result:
    for translation in item.translations:
        print(f"Translated: {translation.text}")
        print(f"Target language: {translation.to}")

Translate to Multiple Languages

result = client.translate(
    body=["Hello, world!"],
    to=["es", "fr", "de", "ja"]  # Spanish, French, German, Japanese
)

for item in result:
    print(f"Source: {item.detected_language.language if item.detected_language else 'unknown'}")
    for translation in item.translations:
        print(f"  {translation.to}: {translation.text}")

Specify Source Language

result = client.translate(
    body=["Bonjour le monde"],
    from_parameter="fr",  # Source is French
    to=["en", "es"]
)

Language Detection

result = client.translate(
    body=["Hola, como estas?"],
    to=["en"]
)

for item in result:
    if item.detected_language:
        print(f"Detected language: {item.detected_language.language}")
        print(f"Confidence: {item.detected_language.score:.2f}")

Transliteration

Convert text from one script to another:

result = client.transliterate(
    body=["konnichiwa"],
    language="ja",
    from_script="Latn",  # From Latin script
    to_script="Jpan"      # To Japanese script
)

for item in result:
    print(f"Transliterated: {item.text}")
    print(f"Script: {item.script}")

Dictionary Lookup

Find alternate translations and definitions:

result = client.lookup_dictionary_entries(
    body=["fly"],
    from_parameter="en",
    to="es"
)

for item in result:
    print(f"Source: {item.normalized_source} ({item.display_source})")
    for translation in item.translations:
        print(f"  Translation: {translation.normalized_target}")
        print(f"  Part of speech: {translation.pos_tag}")
        print(f"  Confidence: {translation.confidence:.2f}")

Dictionary Examples

Get usage examples for translations:

from azure.ai.translation.text.models import DictionaryExampleTextItem

result = client.lookup_dictionary_examples(
    body=[DictionaryExampleTextItem(text="fly", translation="volar")],
    from_parameter="en",
    to="es"
)

for item in result:
    for example in item.examples:
        print(f"Source: {example.source_prefix}{example.source_term}{example.source_suffix}")
        print(f"Target: {example.target_prefix}{example.target_term}{example.target_suffix}")

Get Supported Languages

# Get all supported languages
languages = client.get_supported_languages()

# Translation languages
print("Translation languages:")
for code, lang in languages.translation.items():
    print(f"  {code}: {lang.name} ({lang.native_name})")

# Transliteration languages
print("\nTransliteration languages:")
for code, lang in languages.transliteration.items():
    print(f"  {code}: {lang.name}")
    for script in lang.scripts:
        print(f"    {script.code} -> {[t.code for t in script.to_scripts]}")

# Dictionary languages
print("\nDictionary languages:")
for code, lang in languages.dictionary.items():
    print(f"  {code}: {lang.name}")

Break Sentence

Identify sentence boundaries:

result = client.find_sentence_boundaries(
    body=["Hello! How are you? I hope you are well."],
    language="en"
)

for item in result:
    print(f"Sentence lengths: {item.sent_len}")

Translation Options

result = client.translate(
    body=["Hello, world!"],
    to=["de"],
    text_type="html",           # "plain" or "html"
    profanity_action="Marked",  # "NoAction", "Deleted", "Marked"
    profanity_marker="Asterisk", # "Asterisk", "Tag"
    include_alignment=True,      # Include word alignment
    include_sentence_length=True # Include sentence boundaries
)

for item in result:
    translation = item.translations[0]
    print(f"Translated: {translation.text}")
    if translation.alignment:
        print(f"Alignment: {translation.alignment.proj}")
    if translation.sent_len:
        print(f"Sentence lengths: {translation.sent_len.src_sent_len}")

Async Client

from azure.ai.translation.text.aio import TextTranslationClient
from azure.core.credentials import AzureKeyCredential

async def translate_text():
    async with TextTranslationClient(
        credential=AzureKeyCredential(key),
        region=region
    ) as client:
        result = await client.translate(
            body=["Hello, world!"],
            to=["es"]
        )
        print(result[0].translations[0].text)

Client Methods

MethodDescription
translateTranslate text to one or more languages
transliterateConvert text between scripts
detectDetect language of text
find_sentence_boundariesIdentify sentence boundaries
lookup_dictionary_entriesDictionary lookup for translations
lookup_dictionary_examplesGet usage examples
get_supported_languagesList supported languages

Best Practices

  1. Batch translations — Send multiple texts in one request (up to 100)
  2. Specify source language when known to improve accuracy
  3. Use async client for high-throughput scenarios
  4. Cache language list — Supported languages don't change frequently
  5. Handle profanity appropriately for your application
  6. Use html text_type when translating HTML content
  7. Include alignment for applications needing word mapping

When to Use

This skill is applicable to execute the workflow or actions described in the overview.

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.

Verify signatures and batch/character limits against the pinned SDK and resource API version before using these fragments. Translating text transmits it to the configured cloud service; authorize sensitive content transfer and redact logs. Handle partial item errors, bounded retries and quota limits; constructing a client is not evidence of successful translation.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

00-andruia-consultant

免费有简介

通过检查代码、目标和限制,评估新的或现有的 AI 项目;核对可用目录中的技能后提出建议,并制定包含依赖关系、完成条件和检查方式的任务清单与实施计划。

  • 规划新 AI 项目的启动
  • 梳理现有项目的技术问题
  • 从可用目录中挑选技能
sickn33/agentic-awesome-skills4.8万2026年10月24日 更新

007

免费有简介

检查代码和基础设施中的安全风险,梳理潜在威胁并规划防护改进。涵盖 OWASP 检查、攻击与防御验证及事件响应;操作范围需获明确授权,并结合具体环境验证结果。

  • 审查代码和基础设施安全
  • 用 STRIDE 或 PASTA 梳理威胁
  • 规划安全配置加固
sickn33/agentic-awesome-skills4.8万2026年10月24日 更新

10-andruia-skill-smith

免费有简介

将重复任务整理成 Andru.ia 技能,明确输入、输出、示例和限制;编写 `SKILL.md`,检查目录结构和验证要求,并准备供审阅的拉取请求。

  • 把重复工作整理成技能
  • 改进现有技能的示例或限制
  • 验证技能并准备拉取请求
sickn33/agentic-awesome-skills4.8万2026年10月24日 更新

项目行业确定后,整理行业背景、可能适用的法规、用户熟悉的界面模式、技术选择和风险,并区分已核实事实、假设及待专家确认的事项。

  • 设计前调查行业特有要求
  • 核对目标地区的法规
  • 研究用户熟悉的界面设计
sickn33/agentic-awesome-skills4.8万2026年10月24日 更新

2slides-ppt-generator

免费有简介

通过 2slides API 将文本、提纲或文档制作为演示稿,可参考图片风格、选择主题、添加人工智能旁白,并导出幻灯片图片或音频。

  • 将文本或提纲制作成演示稿
  • 把文档摘要整理成幻灯片
  • 参考图片风格设计幻灯片
sickn33/agentic-awesome-skills4.8万2026年10月24日 更新

360-feedback-system

免费有简介

规划360度评估或同伴反馈流程,并根据已确认的需求创建空白答复台账。可生成字段一致的CSV、SQL、JSON Schema或Notion属性映射,并将可见范围与评分配置分开整理。

  • 设计匿名同伴反馈流程
  • 创建答复记录CSV台账
  • 统一SQL与JSON Schema字段
sickn33/agentic-awesome-skills4.8万2026年10月24日 更新

查看 sickn33 的全部技能

报告此技能的问题