К основному содержанию
скилл

azure-ai-translation-document-py: скилл для Claude Code

Обучает ИИ-агента пакетному переводу файлов Word, PDF и Excel через Azure AI Translator с сохранением исходного форматирования документов.

Установить в Claude Code · Через Skills CLI (Vercel) Все способы и платформы ↓
npx skills add microsoft/skills --skill azure-ai-translation-document-py -a claude-code
Открыть на GitHub

Что делает azure-ai-translation-document-py

Скилл содержит инструкции по использованию официального пакета azure-ai-translation-document. Он объясняет модели, как запускать массовый перевод документов в хранилище Azure Blob Storage с помощью DocumentTranslationClient и как переводить отдельные файлы через SingleDocumentTranslationClient.

Шаблоны кода требуют оборачивать клиенты в контекстный менеджер with для своевременного освобождения сокетов и кэша токенов. Основной путь авторизации ориентирован на DefaultAzureCredential для бесшовной работы с управляемыми удостоверениями Azure, тогда как работа по ключу через AzureKeyCredential оставлена только как устаревший вариант.

Для запуска пакетных заданий обязательно понадобятся ссылки на исходный и целевой контейнеры хранилища с SAS-токенами: AZURE_SOURCE_CONTAINER_URL и AZURE_TARGET_CONTAINER_URL. Без заданного адреса службы в переменной AZURE_DOCUMENT_TRANSLATION_ENDPOINT клиент сразу вернёт ошибку HttpResponseError.

Какие задачи решает

  • настроить пакетный перевод каталога документов в Azure Blob Storage
  • перевести одиночный файл docx с сохранением разметки через SingleDocumentTranslationClient
  • внедрить авторизацию через DefaultAzureCredential вместо небезопасных API-ключей
  • получить список статусов операций перевода через list_translation_statuses

Примеры запросов агенту

  • Напиши Python-скрипт для перевода документов из Azure Storage на испанский и немецкий языки
  • Покажи, как перевести локальный файл document.docx через SingleDocumentTranslationClient
  • Проверь статус завершения пакетного перевода через list_translation_statuses

Как установить azure-ai-translation-document-py

1Через Skills CLI (Vercel)

npx skills add microsoft/skills --skill azure-ai-translation-document-py -a claude-code

2Вручную: положить файлы

~/.claude/skills/azure-ai-translation-document-py/SKILL.md

Папка скилла целиком; для одного проекта — .claude/skills/azure-ai-translation-document-py/

По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов

Вопросы о azure-ai-translation-document-py

Как установить azure-ai-translation-document-py в Claude Code?

Выполните команду npx skills add microsoft/skills --skill azure-ai-translation-document-py -a claude-code. Также можно вручную поместить файл по пути ~/.claude/skills/azure-ai-translation-document-py/SKILL.md.

Что делает скилл azure-ai-translation-document-py?

Он предоставляет агенту готовые примеры интеграции с Python SDK службы Azure Document Translation. Это помогает безошибочно генерировать код для перевода документов Word, Excel и PDF с сохранением их вёрстки.

Какой метод аутентификации использует этот скилл?

Скилл предписывает использовать DefaultAzureCredential, поддерживающий Azure CLI при локальной разработке и управляемые удостоверения в продакшене. Авторизация через AzureKeyCredential допускается только для старых развёртываний, ещё не переведённых на Entra ID.

Исходный текст

SKILL.md · MIT
---
name: azure-ai-translation-document-py
description: |
  Azure AI Document Translation SDK for batch translation of documents with format preservation. Use for translating Word, PDF, Excel, PowerPoint, and other document formats at scale.
  Triggers: "document translation", "batch translation", "translate documents", "DocumentTranslationClient".
license: MIT
metadata:
  author: Microsoft
  version: "1.0.0"
  package: azure-ai-translation-document
---

# Azure AI Document Translation SDK for Python

Client library for Azure AI Translator document translation service for batch document translation with format preservation.

## Installation

```bash
pip install azure-ai-translation-document
```

## Environment Variables

```bash
AZURE_DOCUMENT_TRANSLATION_ENDPOINT=https://<resource>.cognitiveservices.azure.com  # Required for all auth methods
# Storage for source and target documents
AZURE_SOURCE_CONTAINER_URL=https://<storage>.blob.core.windows.net/<container>?<sas>  # Required for all auth methods
AZURE_TARGET_CONTAINER_URL=https://<storage>.blob.core.windows.net/<container>?<sas>  # Required for all auth methods
AZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in production
AZURE_DOCUMENT_TRANSLATION_KEY=<your-api-key>  # Only required for the legacy API-key auth path below
```

## Authentication & Lifecycle

> **🔑 Two rules apply to every code sample below:**
>
> 1. **Prefer `DefaultAzureCredential`.** It works locally (Azure CLI / VS Code / Developer CLI) and in Azure (managed identity, workload identity) with no code change. Avoid connection strings, account/API keys — they bypass Entra audit and rotation.
>    - Local dev: `DefaultAzureCredential` works as-is.
>    - Production: set `AZURE_TOKEN_CREDENTIALS=prod` (or `AZURE_TOKEN_CREDENTIALS=<specific_credential>`) to constrain the credential chain to production-safe credentials.
> 2. **Wrap every client in a context manager** so HTTP transports, sockets, and token caches are released deterministically:
>    - Sync: `with <Client>(...) as client:`
>    - Async: `async with <Client>(...) as client:` **and** `async with DefaultAzureCredential() as credential:` (from `azure.identity.aio`)
>
> Snippets may abbreviate this setup, but production code should always follow both rules.

```python
import os
from azure.identity import DefaultAzureCredential, ManagedIdentityCredential
from azure.ai.translation.document import DocumentTranslationClient

# Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=<specific_credential>
credential = DefaultAzureCredential()
# Or use a specific credential directly in production:
# See https://learn.microsoft.com/python/api/overview/azure/identity-readme?view=azure-python#credential-classes
# credential = ManagedIdentityCredential()

with DocumentTranslationClient(
    endpoint=os.environ["AZURE_DOCUMENT_TRANSLATION_ENDPOINT"],
    credential=credential,
) as client:
    statuses = list(client.list_translation_statuses())
```

### Legacy: API Key (existing keyed deployments)

New code should use `DefaultAzureCredential` above. Use `AzureKeyCredential` only if you have an existing keyed deployment that hasn't been migrated to Entra ID yet — for example, regulated environments still completing their Entra rollout.

```python
import os
from azure.core.credentials import AzureKeyCredential
from azure.ai.translation.document import DocumentTranslationClient, SingleDocumentTranslationClient

with DocumentTranslationClient(
    endpoint=os.environ["AZURE_DOCUMENT_TRANSLATION_ENDPOINT"],
    credential=AzureKeyCredential(os.environ["AZURE_DOCUMENT_TRANSLATION_KEY"]),
) as client:
    statuses = list(client.list_translation_statuses())

# SingleDocumentTranslationClient accepts the same key-based credential.
```

## Basic Document Translation

```python
import os
from azure.ai.translation.document import DocumentTranslationClient, DocumentTranslationInput, TranslationTarget
from azure.core.exceptions import HttpResponseError
from azure.identity import DefaultAzureCredential

credential = DefaultAzureCredential()

with DocumentTranslationClient(
    endpoint=os.environ["AZURE_DOCUMENT_TRANSLATION_ENDPOINT"],
    credential=credential,
) as client:
    source_url = os.environ["AZURE_SOURCE_CONTAINER_URL"]
    target_url = os.environ["AZURE_TARGET_CONTAINER_URL"]

    try:
        # Start translation job
        poller = client.begin_translation(
            inputs=[
                DocumentTranslationInput(
                    source_url=source_url,
                    targets=[
                        TranslationTarget(
                            target_url=target_url,
                            language="es"  # Translate to Spanish
                        )
                    ]
                )
            ]
        )

        # Wait for completion
        result = poller.result()

        print(f"Status: {poller.status()}")
        print(f"Documents translated: {poller.details.documents_succeeded_count}")
        print(f"Documents failed: {poller.details.documents_failed_count}")
    except HttpResponseError as e:
        print(f"Translation failed: {e.message}")
        raise
```

## Multiple Target Languages

```python
poller = client.begin_translation(
    inputs=[
        DocumentTranslationInput(
            source_url=source_url,
            targets=[
                TranslationTarget(target_url=target_url_es, language="es"),
                TranslationTarget(target_url=target_url_fr, language="fr"),
                TranslationTarget(target_url=target_url_de, language="de")
            ]
        )
    ]
)
```

## Translate Single Document

```python
from azure.ai.translation.document import SingleDocumentTranslationClient
from azure.identity import DefaultAzureCredential

with open("document.docx", "rb") as f:
    document_content = f.read()

with SingleDocumentTranslationClient(endpoint, DefaultAzureCredential()) as single_client:
    result = single_client.translate(
        body=document_content,
        target_language="es",
        content_type="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
    )

# Save translated document
with open("document_es.docx", "wb") as f:
    f.write(result)
```

## Check Translation Status

```python
# Get all translation operations
operations = client.list_translation_statuses()

for op in operations:
    print(f"Operation ID: {op.id}")
    print(f"Status: {op.status}")
    print(f"Created: {op.created_on}")
    print(f"Total documents: {op.documents_total_count}")
    print(f"Succeeded: {op.documents_succeeded_count}")
    print(f"Failed: {op.documents_failed_count}")
```

## List Document Statuses

```python
# Get status of individual documents in a job
operation_id = poller.id
document_statuses = client.list_document_statuses(operation_id)

for doc in document_statuses:
    print(f"Document: {doc.source_document_url}")
    print(f"  Status: {doc.status}")
    print(f"  Translated to: {doc.translated_to}")
    if doc.error:
        print(f"  Error: {doc.error.message}")
```

## Cancel Translation

```python
# Cancel a running translation
client.cancel_translation(operation_id)
```

## Using Glossary

```python
from azure.ai.translation.document import TranslationGlossary

poller = client.begin_translation(
    inputs=[
        DocumentTranslationInput(
            source_url=source_url,
            targets=[
                TranslationTarget(
                    target_url=target_url,
                    language="es",
                    glossaries=[
                        TranslationGlossary(
                            glossary_url="https://<storage>.blob.core.windows.net/glossary/terms.csv?<sas>",
                            file_format="csv"
                        )
                    ]
                )
            ]
        )
    ]
)
```

## Supported Document Formats

```python
# Get supported formats
formats = client.get_supported_document_formats()

for fmt in formats:
    print(f"Format: {fmt.format}")
    print(f"  Extensions: {fmt.file_extensions}")
    print(f"  Content types: {fmt.content_types}")
```

## Supported Languages

```python
# Get supported languages
languages = client.get_supported_languages()

for lang in languages:
    print(f"Language: {lang.name} ({lang.code})")
```

## Async Client

```python
from azure.ai.translation.document.aio import DocumentTranslationClient
from azure.identity.aio import DefaultAzureCredential

async def translate_documents():
    async with DefaultAzureCredential() as credential:
        async with DocumentTranslationClient(
            endpoint=endpoint,
            credential=credential,
        ) as client:
            poller = await client.begin_translation(inputs=[...])
            result = await poller.result()
```

## Supported Formats

| Category | Formats |
|----------|---------|
| Documents | DOCX, PDF, PPTX, XLSX, HTML, TXT, RTF |
| Structured | CSV, TSV, JSON, XML |
| Localization | XLIFF, XLF, MHTML |

## Storage Requirements

- Source and target containers must be Azure Blob Storage
- Use SAS tokens with appropriate permissions:
  - Source: Read, List
  - Target: Write, List

## Best Practices

1. **Pick sync OR async and stay consistent.** Do not mix `azure.xxx` sync clients with `azure.xxx.aio` async clients in the same call path. Choose one mode per module.
2. **Always use context managers for clients and async credentials.** Wrap every client in `with Client(...) as client:` (sync) or `async with Client(...) as client:` (async). For async `DefaultAzureCredential` from `azure.identity.aio`, also use `async with credential:` so tokens and transports are cleaned up.
3. **Use SAS tokens** with minimal required permissions
4. **Monitor long-running operations** with `poller.status()`
5. **Handle document-level errors** by iterating document statuses
6. **Use glossaries** for domain-specific terminology
7. **Separate target containers** for each language
8. **Use async client** for multiple concurrent jobs
9. **Check supported formats** before submitting documents

## Reference Files

| File | Contents |
|------|----------|
| [references/capabilities.md](references/capabilities.md) | Additional non-hero capabilities, operation-group coverage, and production checklists. |
| [references/non-hero-scenarios.md](references/non-hero-scenarios.md) | Dedicated non-hero examples for secondary/advanced scenarios. |

© Microsoft · MIT · microsoft/skills

Похожие скиллы

Все скиллы по теме «Облака: AWS, Azure, GCP» →
caveman-manage JuliusBrussee Проверяет состояние и результаты экспериментов Caveman Cloud, предлагает одно действие или блокирует рискованный запрос. Нужен перед запуском, одобрением, отменой или откатом. CX Codex +1 104 200установок workers-best-practices cloudflare Скилл настраивает ИИ на проверку продакшен-кода Cloudflare Workers по актуальным правилам рантайма, типам Wrangler и антипаттернам. CX Codex +1 126 100установок cloudflare-email-service cloudflare Скилл для работы с Cloudflare Email Sending и Email Routing: помогает настроить отправку и приём писем в Workers. CX Codex +1 102 300установок firebase-basics официальный google Скилл настраивает Firebase CLI, помогает войти в аккаунт, создать или выбрать проект и скачать конфигурацию Android или iOS. CX Codex 14 100установок cloudflare-one cloudflare Помогает агенту проектировать, настраивать и разбирать развёртывания Cloudflare One Zero Trust и SASE. Пригодится, когда нужно спланировать Access, Gateway или туннели без похода в документацию вручную. CX Codex +1 93 100установок cloudflare-one-migrations cloudflare Помогает спланировать переход с VPN, SWG или SASE на Cloudflare One: сопоставляет политики, находит пробелы и расписывает порядок выката. CX Codex +1 89 500установок

Из того же набора207

Весь набор →
azure-containerregistry-py Скилл подсказывает, как работать с Azure Container Registry через Python: репозитории, образы, манифесты и теги. Нужен при задачах с ACR. 2установок azure-appconfiguration-py Скилл учит агента работать с Azure App Configuration из Python: читать и записывать настройки, включать фича-флаги, снимать снапшоты. 2установок azure-ai-vision-imageanalysis-py Скилл помогает работать с Azure AI Vision Image Analysis SDK на Python: извлекать текст, находить объекты и получать подписи к изображениям. Пригодится для задач компьютерного зрения. 2установок azure-ai-translation-text-py Скилл по Python SDK Azure AI Translator: перевод текста, транслитерация, определение языка и словарные статьи. Пригодится, когда в приложении нужно переводить строки на лету. 2установок azure-ai-transcription-py Скилл помогает писать Python-код для Azure AI Transcription: преобразовывать речь в текст пакетно или в реальном времени. Пригодится для расшифровки записей с отметками времени и разделением говорящих. 2установок azure-ai-textanalytics-py Скилл для работы с Azure AI Language из Python: тональность, сущности, ключевые фразы, определение языка, поиск персональных данных и медицинский NLP. 2установок azure-ai-ml-py Скилл помогает писать Python-код для управления ресурсами Azure Machine Learning: рабочими областями, заданиями, моделями, данными и вычислениями. Пригодится для настройки ML-проекта и запуска обучения. 2установок azure-ai-contentsafety-py Скилл помогает подключить Azure AI Content Safety SDK для Python и проверять текст и изображения на вредный контент. Подходит для модерации в приложении. 2установок

Спонсоры проекта

Компании, которые помогают держать аналитику открытой