A translation prompt should state source and target locale, audience, approved glossary, protected product names, and the exact strings that must remain machine-readable. Translation quality and placeholder integrity are separate checks. The model may choose natural wording around a token, but it must not rename, drop, duplicate, or translate a named placeholder. Validate the token multiset in the application, then review meaning and tone with a competent speaker. This small validator handles simple brace-delimited names; a product using nested message syntax needs a parser for that syntax rather than a regular expression.
Translation prompts: preserve terms and machine placeholders
Operational case
A parcel service localizes a dispatch notice for French-speaking customers in Canada. The English source includes shipment_id and dispatch_date variables. A draft reads naturally but replaces dispatch_date with date_depart; the renderer would leave an unresolved token. Another draft preserves both tokens but changes the approved service name. The assistant receives a glossary and a note that the product name stays unchanged. The application compares placeholder counts, while a reviewer checks that the departure meaning and level of formality survive. The date value remains structured data until the locale formatter renders it.
from collections import Counter
import re
source_notice = "Shipment {shipment_id} is scheduled for {dispatch_date}."
localized_notice = "L'expédition {shipment_id} est prévue pour le {dispatch_date}."
placeholder_pattern = re.compile(r"\{([a-z][a-z0-9_]*)\}")
def placeholder_counts(message: str) -> Counter:
return Counter(placeholder_pattern.findall(message))
if placeholder_counts(source_notice) != placeholder_counts(localized_notice):
raise ValueError("localized placeholders differ from source")
print("placeholder check: pass")Performance and operating cost
For S source strings and total length L, simple placeholder scanning is O(L) time and O(P) space for P distinct placeholder names. Human meaning review is the larger cost; a token match cannot detect a mistranslated warning or changed promise. Batch strings by feature with context, not as unrelated fragments, so terminology stays consistent. Record glossary version and locale tag with the generated draft. A second model pass may catch an omission, but it does not replace deterministic token validation or a qualified language review for consequential copy.
Common Mistakes
- Do not translate a machine placeholder into a new identifier.
- Do not assume matching placeholders prove semantic accuracy.
- Do not send an ICU-style nested message through a simple brace matcher.
Connected lessons
- Prompt engineering applications
- Prompt Engineering
- Prompt templates: bind variables without changing instruction structure
- Multilingual prompts: test policy meaning across languages
- Python Unicode normalization: equality is not visual identity
- Locale-aware prompts: keep values typed until rendering
- Mixed-language requests: separate intent from reply language
- Cross-language retrieval: keep policy meaning attached to its source
- Cross-locale evaluation: compare decisions, not word-for-word text
- Project: release a multilingual order notice safely
- Multilingual prompt workflow decisions
Continue with: Localization prompts: define the locale and message contract.
