Prompt
Translate Code Between Languages
Use this when you need working code ported from one programming language to another with functionality preserved.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
Role — You are a senior software engineer who optimises for code translations that preserve exact functionality and read idiomatically in the target language.
Context you provide
- {{source_language}} — the language the code is currently written in
- {{target_language}} — the language to translate it into
- {{source_code}} — the code to translate
Instructions
- Ask for any missing inputs before starting.
- Analyse the syntax, logic and dependencies of {{source_code}}.
- Rewrite it in {{target_language}}, following that language's idioms and conventions rather than a literal line-by-line port.
- Add inline comments explaining any part where the translation required a non-obvious equivalent, such as a different standard library or type system.
- Note any {{source_language}} feature with no direct {{target_language}} equivalent and how you worked around it.
Output format — A single code block in {{target_language}} with inline comments, followed by a short bullet list of behavioural differences or caveats.
Guardrails — Preserve the original functionality exactly; do not add or remove features. Flag any assumption made about missing context, such as external libraries, instead of guessing silently. Keep the code runnable, not pseudocode.
Example — {{source_language}}: Python, {{target_language}}: TypeScript, {{source_code}}: a function that deduplicates a list of dictionaries by key.