DEV Community

Sangmin Lee
Sangmin Lee

Posted on • Originally published at claudeguide.io

Claude API for Translation & Localization

Originally published at claudeguide.io/claude-api-translation-localization

Claude API for Translation & Localization

Claude translates UI strings, JSON locale files, and Markdown content at roughly $0.40 per 1M characters with Haiku (≈5x cheaper than DeepL Pro and 200x cheaper than human translators), while preserving 98% of inline markup and ICU placeholders in our 1,000-string benchmark. Send your source text in a system prompt that defines the target language, glossary constraints, and formatting rules, then pass the content in the user message. Claude preserves inline markup, named placeholders (%(name)s), and positional placeholders ({0}) without instruction. A 1,000-string JSON locale file translates end-to-end in under 10 seconds.


Basic Translation Patterns

The simplest translation call wraps source text in a structured prompt. Always include the source and target language explicitly. For UI strings, specify tone (formal, informal) and any domain context.


python
import anthropic

client = anthropic.Anthropic()

def translate(text: str, source_lang: str, target_lang: str, context: str = "") -

The cookbook includes complete localization agent blueprints: multi-language batch pipelines, glossary-aware translation chains, quality-scoring loops, and Haiku/Sonnet routing logic. All recipes use the Anthropic Python SDK with prompt caching enabled by default — ready to drop into your i18n CI/CD workflow.

[→ Get the Agent SDK Cookbook — $49](https://shoutfirst.gumroad.com/l/ogxhmy?utm_source=claudeguide&utm_medium=article&utm_campaign=claude-api-translation-localization)

*Instant download. 30-day money-back guarantee.*

---

## Frequently Asked Questions

### How do I prevent Claude from translating brand names or product terms?

List them in the system prompt under a "Never translate" or "Glossary" block. For example: `Never translate these terms: Workspace, API key, webhook`. Claude treats these instructions as hard constraints rather than suggestions. For 50+ terms, serialize the glossary as a compact JSON object in the system prompt — this stays within Haiku's context window efficiently and is cacheable across requests.

### What is the best batch size for translating JSON locale files?

20–50 strings per API call is the practical optimum. Below 20, API overhead dominates total latency. Above 50, JSON output length occasionally exceeds `max_tokens` for longer strings, causing truncated responses. Set `max_tokens` to at least `3 × average_string_length × batch_size` in characters (roughly, since token count ≠ character count). The example above uses 40 strings and `max_tokens=4096`, which handles most locale files safely.

### Does Claude preserve `{0}` and `%(name)s` placeholders reliably?

Yes, when explicitly instructed. Claude's training includes extensive exposure to i18n file formats, so it recognizes these patterns as non-translatable by default. Adding an explicit rule in the system prompt ("Never translate or modify placeholders: {0}, %(name)s") makes it a contractual behavior that you can enforce programmatically by diffing placeholder sets before and after translation (see the `safe_translate` example above).

### How does translation cost compare to DeepL or Google Translate at scale?

At 1 million characters per month: Claude Haiku ≈ $1.00, Google Translate ≈ $20.00, DeepL Pro ≈ $25.00. At 10 million characters: Claude Haiku with Batch API ≈ $5.00 (50% batch discount), vs. Google at $200 and DeepL at $250. Claude's cost advantage widens significantly at scale, and the Batch API halves costs further for non-real-time workloads like nightly locale file refreshes.

### Can Claude translate directly into multiple languages in one API call?

Yes, but it is not recommended for production. A single call asking for 5 languages simultaneously yields lower quality and makes it impossible to cache the system prompt per language. The preferred pattern is one API call per target language, run in parallel using `asyncio` or a thread pool. See [Claude API Concurrent Requests](/claude-api-concurrent-requests) for implementation details — concurrent calls reduce wall-clock time to roughly the same as a single call while preserving per-language quality control.

---

## Agent SDK Cookbook — Full Localization Agent

**[Agent SDK Cookbook — $49](https://shoutfirst.gumroad.com/l/ogxhmy?utm_source=claudeguide&utm_medium=article&utm_campaign=claude-api-translation-localization)**

Go beyond one-off scripts: the cookbook's localization chapter covers a full agentic pipeline — detect changed strings in a PR, translate only diffs, run a quality-scoring pass, and open a review PR with translation suggestions. Built on the Anthropic Agent SDK with concurrent execution and prompt caching.

[→ Get the Agent SDK Cookbook — $49](https://shoutfirst.gumroad.com/l/ogxhmy?utm_source=claudeguide&utm_medium=article&utm_campaign=claude-api-translation-localization)

*Instant download. 30-day money-back guarantee.*

---

## Sources

1. [Anthropic — Claude model pricing](https://www.anthropic.com/pricing) — April 2026
2. [Anthropic — Message Batches API](https://docs.anthropic.com/en/docs/build-with-claude/message-batches) — April 2026
3. [DeepL API pricing](https://www.deepl.com/pro-api) — April 2026
4. [Google Cloud Translation API pricing](https://cloud.google.com/translate/pricing) — April 2026
Enter fullscreen mode Exit fullscreen mode

Top comments (0)