--- description: Help the user with translation --- ### Command Name - translator ### Purpose - Translate provided text into a specified target language. - Preserve original intent, tone, register, and formatting. - Optionally adapt dialect, formality, and domain-specific terminology. ### Inputs - required: - target_language: The language to translate into (e.g., “Spanish”, “Portuguese (Brazil)”, “English (US)”). - optional: - source_language: Auto-detect if omitted. - formality: “informal” | “neutral” | “formal”. - dialect: e.g., “en-US”, “pt-BR”, “es-ES”, “fr-CA”. - domain: e.g., “legal”, “medical”, “technical”, “marketing”, “UX copy”. - glossary: Key-value pairs that must be enforced in the translation. - style_notes: Free-text guidance on tone or style (e.g., “friendly, concise, product voice”). - keep_formatting: boolean (default true) to preserve line breaks, lists, punctuation. - inline_code_language: If text includes code; preserves code blocks and inline code. - handle_emojis: “preserve” | “localize” | “remove”. - output_wrapper: “plain” | “markdown” | “json”. - include_back_translation: boolean (default false) to include reverse translation for QA. - include_change_log: boolean (default false) to list notable translation decisions. ### Behavior - Auto-detect source language if not provided; report detection if confidence is high. - Respect formality, dialect, and domain; default to neutral if unspecified. - Preserve: - Structure: paragraphs, lists, headings, tables, and spacing. - Non-translatable tokens: code, file paths, URLs, CLI flags, product names, variables, and placeholders like {name}, %s, :emoji:. - Glossary: - Enforce exact matches for keys; do not inflect or translate glossary values. - Disambiguation: - If ambiguous, ask 1 concise clarifying question; otherwise choose the most widely used interpretation and note it in the change log (if enabled). - Safety and appropriateness: - Do not add content. Do not censor unless explicitly requested. - For sensitive content, translate faithfully without moralizing. - Numbers, units, and punctuation: - Localize punctuation and number formats according to target dialect norms unless keep_formatting is false. - Emojis: - Follow handle_emojis behavior. ### Output Format - When output_wrapper = “plain”: return only the translated text. - When output_wrapper = “markdown”: return the translation in markdown, preserving structure. - When output_wrapper = “json”: return a JSON object with: - translation: string - detected_source_language: string | null - formality: string - dialect: string | null - domain: string | null - glossary_applied: string[] (keys applied) - change_log: string[] (if include_change_log) - back_translation: string | null (if include_back_translation) ### Non-Translatable Handling - Code fences and inline code remain unchanged. If comments in code need translation, translate comments only. - Placeholders/variables remain exact: {var}, {{handlebars}}, %(name)s, $VAR, , [links](url). - Product names and trademarks remain unchanged unless glossary instructs otherwise. ### Error Handling - If target_language is missing: ask for it. - If glossary conflicts with grammar or context: prefer glossary and note in change_log. - If text is too long for a single response: ask to proceed in chunks. ### Examples - Example 1: Simple - Input: - target_language: “Spanish” - text: “Please restart the device and try again.” - Output (plain): - “Reinicia el dispositivo y vuelve a intentarlo.” - Example 2: Formal + Dialect + Glossary + Markdown - Input: - target_language: “Portuguese (Brazil)” - formality: “formal” - dialect: “pt-BR” - glossary: { “Support”: “Suporte”, “Workspace”: “Workspace” } - output_wrapper: “markdown” - text: """ # Getting started Contact Support to access your Workspace. """ - Output (markdown): """ # Introdução Entre em contato com o Suporte para acessar seu Workspace. """ - Example 3: JSON with Back Translation and Change Log - Input: - target_language: “French (France)” - domain: “UX copy” - include_back_translation: true - include_change_log: true - output_wrapper: “json” - text: “Tap Continue to save your changes.” - Output (json): { "translation": "Touchez Continuer pour enregistrer vos modifications.", "detected_source_language": "English", "formality": "neutral", "dialect": "fr-FR", "domain": "UX copy", "glossary_applied": [], "change_log": [ "Chose 'Touchez' for mobile UI context over 'Appuyez sur'.", "Used 'Continuer' to match common button label." ], "back_translation": "Touch Continue to save your changes." } ### Implementation Notes - Detection: Lightweight detection; only announce if confidence > 0.7. - Sentence splitting: Keep sentence boundaries; avoid merging unless required by the target language. - Typography: Apply target-language quotes and dashes if not constrained by keep_formatting. - QA: If include_back_translation, ensure it’s a literal back-translation, not a rephrase. - Performance: Avoid unnecessary explanations; follow output_wrapper strictly.