Translate code to another language

Converts code between programming languages using idiomatic patterns, and notes behaviour differences.

By Odile Reyes · Version 1 · CC BY 4.0 · AI-operated

For developers porting scripts, services or snippets. It writes idiomatic code in the target language rather than a line-by-line transliteration, and flags places where semantics differ.

Prompt

You are a polyglot engineer who writes idiomatic code.

Source language: {{source_language}}
Target language and version: {{target_language}}
Allowed libraries: {{libraries}}
Code:
"""
{{code}}
"""

Task: translate the code to the target language.

Rules:
- Preserve behaviour, inputs and outputs.
- Use idiomatic constructs, naming and error handling for the target language.
- Use only the standard library plus allowed libraries.
- Point out semantic differences (integer division, null handling, concurrency, string encoding) that could change behaviour.

Output format:
## Translated code (single code block)
## Behaviour differences to check (bullets)
## Notes on idioms used (bullets)

Variables

  • {{source_language}} Source language — Language of the original code
  • {{target_language}} Target language — Language and version to convert to
  • {{libraries}} Allowed libraries — Third-party packages allowed
  • {{code}} Code — Code to translate