How to Use Local LLMs for Translation and Multilingual Tasks

Modern local LLMs are genuinely capable translators. Multilingual models trained on diverse language data handle translation well across dozens of language pairs — often at quality approaching machine translation services for common languages, and with the significant advantage of running entirely on your hardware. This guide covers how to use Ollama for translation tasks, which models perform best, and practical workflows for both single documents and bulk translation jobs.

Why Local Translation?

The case for local translation has three components. Privacy: translating confidential documents, client communications, internal materials, or personal content through cloud services means that content leaves your control. Local translation keeps sensitive text on your machine. Cost: cloud translation APIs charge per character — at scale, translating large volumes of text through DeepL or Google Translate API generates meaningful costs. A local model translates unlimited text for free after the initial hardware and model setup. Customisation: local models can be prompted to follow specific style guides, terminology requirements, or domain conventions that cloud translation services cannot easily accommodate.

Best Models for Translation

Not all Ollama models translate equally well. Strong multilingual capability requires training data across many languages. The top performers:

Llama 3.1 (8B and 70B): Strong multilingual performance across major European languages, Chinese, Japanese, Korean, Arabic, and dozens more. The 8B version handles common translation tasks competently; the 70B version produces noticeably more natural, idiomatic translations for nuanced text. Best choice for most translation needs.

Qwen 2.5 (7B and 72B): Particularly strong on Chinese-English translation and other CJK (Chinese, Japanese, Korean) language pairs, reflecting Alibaba’s training data emphasis. If you do significant CJK translation work, Qwen 2.5 often outperforms Llama 3.1 on these specific pairs.

Mistral models: Strong on European language pairs (French, Spanish, Italian, German, Portuguese) given the training data composition. Good choice for European language translation workflows.

What to avoid: Small models (3B and below) produce lower quality translations, particularly for languages with complex grammar or significant distance from English. For translation quality, model size matters more than it does for simple classification tasks.

Basic Translation Function

import ollama

def translate(text: str, target_lang: str, source_lang: str = "auto",
              style: str = "natural") -> str:
    source_desc = f"from {source_lang} " if source_lang != "auto" else ""
    style_notes = {
        "natural": "Produce natural, idiomatic translation that reads as if originally written in the target language.",
        "literal": "Produce a faithful, close translation that preserves the structure of the source text.",
        "formal": "Use formal register appropriate for professional or official documents.",
        "casual": "Use casual, conversational register."
    }
    style_instruction = style_notes.get(style, style_notes["natural"])

    response = ollama.chat(
        model="llama3.1",
        messages=[
            {
                "role": "system",
                "content": f"You are an expert translator. {style_instruction} Return only the translated text, nothing else."
            },
            {
                "role": "user",
                "content": f"Translate {source_desc}to {target_lang}:\n\n{text}"
            }
        ],
        options={"temperature": 0.2, "num_ctx": 8192}
    )
    return response["message"]["content"].strip()

# Examples
print(translate("The meeting has been rescheduled to Thursday.", "French"))
print(translate("Veuillez trouver ci-joint notre proposition.", "English", style="formal"))
print(translate("The results exceeded all expectations.", "Japanese", style="natural"))

Temperature 0.2 balances consistency with natural variation — lower temperatures produce more consistent but sometimes stilted translations; higher temperatures risk introducing errors. For critical translations, run at temperature 0 for reproducibility and verify against the source.

Batch Document Translation

import os
from pathlib import Path

def translate_file(input_path: str, target_lang: str, output_path: str = None) -> str:
    text = Path(input_path).read_text(encoding="utf-8")
    # Split into chunks for long documents (max ~2000 chars per chunk)
    chunks =  for i in range(0, len(text), 2000)]
    # Find natural split points at paragraph boundaries
    translated_chunks = [translate(chunk, target_lang) for chunk in chunks]
    translated = "\n\n".join(translated_chunks)
    if output_path:
        Path(output_path).write_text(translated, encoding="utf-8")
    return translated

def translate_directory(input_dir: str, target_lang: str, output_dir: str):
    Path(output_dir).mkdir(exist_ok=True)
    for filepath in Path(input_dir).glob("*.txt"):
        output_path = Path(output_dir) / filepath.name
        print(f"Translating {filepath.name}...")
        translate_file(str(filepath), target_lang, str(output_path))
    print(f"Done. Translated files saved to {output_dir}")

# Batch translate a folder of text files to Spanish
translate_directory("./english_docs", "Spanish", "./spanish_docs")

Figure 1 — Local LLM Translation Quality by Language Pair

Language pairQuality (7B model)Best local modelvs DeepLEnglish ↔ French / Spanish / GermanExcellentLlama 3.1 or MistralCloseEnglish ↔ Chinese / Japanese / KoreanVery goodQwen 2.5Good, not equalEnglish ↔ Arabic / Hindi / TurkishGoodLlama 3.1Noticeable gapNon-English ↔ Non-EnglishVariableLlama 3.1 70BSignificant gapLow-resource languagesLimitedLargest model availableLarge gap

Domain-Specific Translation with Custom Terminology

One significant advantage of local LLMs over dedicated machine translation services is the ability to enforce custom terminology through prompting. Legal, medical, technical, and other domain-specific translations often require specific term choices that standard MT systems do not honour. A glossary-aware translation prompt addresses this:

def translate_with_glossary(text: str, target_lang: str,
                            glossary: dict[str, str]) -> str:
    glossary_text = "\n".join(f"- '{k}' must be translated as '{v}'"
                               for k, v in glossary.items())
    response = ollama.chat(
        model="llama3.1",
        messages=[{
            "role": "system",
            "content": f"""You are a professional translator. Translate to {target_lang}.

Mandatory terminology (follow exactly):
{glossary_text}

Return only the translated text."""
        },
        {"role": "user", "content": text}],
        options={"temperature": 0.1, "num_ctx": 8192}
    )
    return response["message"]["content"].strip()

# Example: medical translation with required terminology
med_glossary = {
    "myocardial infarction": "infarto de miocardio",
    "hypertension": "hipertensión arterial",
    "anticoagulant therapy": "terapia anticoagulante"
}
text = "Patient presents with myocardial infarction complicated by hypertension. Anticoagulant therapy initiated."
print(translate_with_glossary(text, "Spanish", med_glossary))

The glossary approach works well for 5-20 key terms. For larger terminology databases (hundreds of terms), consider a retrieval-augmented approach where you identify relevant terms in the source text first, then include only the matching glossary entries in the translation prompt.

Multilingual Classification and Analysis

Beyond translation, local LLMs handle multilingual classification tasks well — analysing sentiment, classifying content, or extracting information from text in languages other than English. If your customers write to you in French, Spanish, German, and Portuguese, a local model can classify their messages without first translating them to English. This reduces a two-step pipeline (translate then classify) to one step and avoids any quality loss from intermediate translation. Prompt in English, provide the non-English text, and ask for the classification in English — models handle this cross-lingual inference reliably for major languages and the classification quality is comparable to working in a single language.

Quality Assessment: When to Use Local vs Cloud Translation

Local LLM translation quality for common language pairs (English to and from French, Spanish, German, Italian, Portuguese, Chinese, Japanese, Korean) is excellent with a capable 7B+ model. For published content, certified translations, legal translations, and other high-stakes use cases, always have a qualified human translator review and certify the output regardless of whether it came from a local model or a cloud service. For internal documents, informal communications, draft translations for review, and bulk processing where 90% quality is adequate, local models are often indistinguishable from cloud MT services on major language pairs. For less common languages, non-English to non-English translation, or languages with complex morphology and limited training data representation, quality drops and cloud services with dedicated translation models (DeepL, Google Translate) typically outperform general-purpose LLMs. The practical rule: test your specific language pairs and document types against the alternatives, and make the decision based on observed quality rather than general claims.

Translation at Scale: Performance Considerations

For bulk translation jobs — translating a product catalogue, localising a documentation site, processing a backlog of customer communications — local translation performance matters. A 7B model on a modern GPU translates roughly 1,000-3,000 words per minute depending on hardware and response length. At this rate, translating 100,000 words (a typical product documentation site) takes 30-100 minutes. Cloud translation services operate faster for bulk jobs but incur per-character costs that accumulate significantly at this scale. For recurring translation workloads, the local model pays for itself quickly. Use async processing with multiple translation requests in flight (matching OLLAMA_NUM_PARALLEL) to maximise throughput for batch jobs. Store translated content in a cache keyed by source text hash to avoid re-translating identical content that appears across multiple documents.

Language Detection

For pipelines processing multilingual input where the source language is unknown, asking the model to detect the language before translating adds a reliable classification step:

def detect_language(text: str) -> str:
    response = ollama.chat(
        model="llama3.2:3b",
        messages=[{
            "role": "system",
            "content": "Identify the language of the text. Reply with only the language name in English (e.g. French, Spanish, Japanese). No other text."
        },
        {"role": "user", "content": text[:200]}],  # first 200 chars is enough
        options={"temperature": 0, "num_predict": 20}
    )
    return response["message"]["content"].strip()

def auto_translate(text: str, target_lang: str) -> dict:
    source_lang = detect_language(text)
    if source_lang.lower() == target_lang.lower():
        return {"translated": text, "source_lang": source_lang, "skipped": True}
    translated = translate(text, target_lang, source_lang=source_lang)
    return {"translated": translated, "source_lang": source_lang, "skipped": False}

Language detection with a small model is fast and reliable for common languages — a 3B model correctly identifies the language of a text in under a second. Combine detection and translation in a single pipeline for processing multilingual content at scale.

Practical Limitations to Know

Local LLM translation has a few consistent limitations worth knowing before committing to it for specific use cases. Idiomatic expressions, humour, wordplay, and culturally embedded references translate poorly in both directions — this is true of all MT systems but can be more pronounced with smaller models. Very long documents translated as single chunks risk the model losing context toward the end; chunking at natural paragraph boundaries addresses this but requires careful reassembly. Right-to-left languages (Arabic, Hebrew) and languages with complex scripts sometimes have formatting issues in the model output — the semantic translation quality may be good but the rendered text needs post-processing for display. And as noted above, non-English to non-English translation pairs (French to Japanese, for example) receive less training signal than pairs involving English, and quality is more variable. For any of these edge cases, test on representative examples before committing to a local-only approach for that specific language pair and content type.

Getting the Most from Local Translation

The practical path to high-quality local translation: start by testing your specific language pairs with real examples from your domain. Compare the output from Llama 3.1 8B, Llama 3.1 70B if you have the hardware, and Qwen 2.5 for CJK pairs. Evaluate not just accuracy but naturalness — does the translation read as if it was written by a native speaker, or does it carry the grammatical structure of the source language? For professional or published content, build in a review step where a qualified human checks the output before it goes live. For internal, informal, or bulk content, the efficiency gains from local translation are immediate and substantial, and quality at this tier is usually adequate without systematic human review. Local translation is a genuinely mature capability in 2026 — for the language pairs and use cases where it works well, it is a compelling replacement for cloud translation services, and understanding its limitations tells you exactly where to set up that review step.

Beyond Translation: Other Multilingual Use Cases

Local multilingual LLMs enable several useful tasks beyond direct translation. Cross-lingual question answering: ask questions in English about documents written in French, Spanish, or Japanese, and the model retrieves and synthesises information across the language barrier. This works particularly well for research and analysis workflows where you need to understand foreign-language sources without fully translating them. Multilingual summarisation: summarise a French document into English bullet points, or produce a Spanish executive summary from English source material. Style transfer across languages: translate while simultaneously adjusting the register — producing a formal German version from a casual English draft, for example. Named entity extraction from multilingual text: extract names, organisations, locations, and dates from documents in multiple languages and consolidate them into a unified English-language structured format. Each of these tasks benefits from the same local, private infrastructure as straight translation, and local LLMs handle all of them with the single model you already have running for translation.

Leave a Comment