Artificial IntelligenceAnthropicProjects

Build a Multi-Language Translator App with Claude API

TT
TopicTrick
Build a Multi-Language Translator App with Claude API

What Does This Translation App Do?

This project builds a FastAPI-backed translation service that accepts text in any language, detects the source language automatically, translates with awareness of formality level (formal, neutral, informal) and domain (legal, medical, marketing, technical), validates quality via back-translation, and returns structured JSON results — all powered by Claude's language understanding rather than a word-substitution engine.

Machine translation has existed for decades. The difference between traditional translation engines and Claude-powered translation becomes most apparent when text requires cultural sensitivity, tone preservation, or domain-specific precision. A legal contract translated by a generic translation engine may be grammatically correct but use the wrong formality register for a given jurisdiction. Marketing copy may translate accurately but lose all of its emotional impact.

Claude translates with awareness of context, tone, formality, and domain. This project builds a multi-language translator application with a FastAPI backend that handles detection, translation, quality validation, and tone adjustment — all through structured API endpoints.


What We Are Building

The translator application provides:

  1. Automatic language detection: Identify the source language without the user specifying it
  2. Context-aware translation: Translate with awareness of domain (legal, medical, technical, business, casual) and formality level
  3. Back-translation quality check: Translate back to the original language and score deviation from the original to measure translation quality
  4. REST API: A FastAPI service that any frontend can call

Prerequisites

  • Python 3.9 or later
  • pip install anthropic fastapi uvicorn pydantic
  • An Anthropic API key set as ANTHROPIC_API_KEY

Core Translation Logic

python

FastAPI REST API

python

Use Haiku for Detection and Quality Checks

Language detection and back-translation quality checks are tasks where speed and cost matter more than reasoning depth. Claude Haiku 4.5 is significantly cheaper and faster than Sonnet, and handles these structured tasks reliably. Reserve Sonnet for the actual translation step where nuance and domain accuracy genuinely require the more capable model.


    Extending the Project

    • Batch translation: Add an endpoint that accepts an array of strings and translates them in a single API call, using the Batch API for 50% cost reduction on large workloads
    • Glossary enforcement: Accept a custom glossary of terms (product names, branded terms) that must remain untranslated or use specific approved translations
    • Translation memory: Cache previously translated segments in a database and reuse them for repeated phrases — significantly reducing cost and improving consistency in large document translation
    • Streaming: Use the streaming API to display translation character by character in a web UI, improving perceived responsiveness for long documents

    Summary

    Claude's translation capability goes well beyond word-for-word substitution. The domain and formality parameters in this project illustrate what makes Claude-powered translation more useful for professional contexts than a generic translation engine.

    • Use Haiku for detection and quality checks — fast structural tasks where model depth does not matter
    • Use Sonnet for translation — where domain and cultural nuance require genuine language understanding
    • Use back-translation quality checks for mission-critical content (legal, medical) where catching mistranslations is essential
    • Pass domain and formality context in every translation request — it dramatically improves output relevance

    Moving from beginner projects to intermediate IT professional builds, next up: Project: Build a RAG App with Claude — Query Your Own Documents.

    For the Claude model selection behind this project (Haiku for detection, Sonnet for translation), see Claude Model Family: Opus, Sonnet, and Haiku and Claude API Pricing and Tokens Explained. To add structured output guarantees to translation results, see Claude Structured Outputs and JSON.

    External Resources


    This post is part of the Anthropic AI Tutorial Series. Previous post: Project: Build a Code Review Assistant for GitHub PRs.