wowprompt

Translate code from one programming language to another

Converts a pasted piece of code into another language using that language's own idioms and libraries, with notes on behaviour that changes. Use it when porting a script, moving a service to a new stack or learning a language from code you already know.

The translated code in one block, a mapping table of libraries and constructs used, behaviour differences, and tests that confirm both versions match
The output this prompt produced, unedited.

The prompt

Goal

Produce working, idiomatic code in the target language that behaves the same as the original, and say clearly where exact equivalence is not possible.

Inputs

  • Source language and version: [e.g. Python 3.12]
  • Target language and version: [e.g. TypeScript 5, Node 20]
  • Code: [paste]
  • What the code is for: [one or two lines]
  • Libraries allowed in the target: [standard library only, or list]

Steps

  1. Summarise what the code does in three to five lines.
  2. Map each external library and language feature to its target equivalent.
  3. Translate, using the target's naming conventions, error handling and types.
  4. List differences in behaviour, such as integer division, string encoding, date handling or null values.
  5. Write tests that pass on both versions.

Output format

  1. Summary.
  2. | Source construct or library | Target equivalent | Note |
  3. Translated code in one block.
  4. Behaviour differences, numbered.
  5. Test cases with input and expected output.

Check before answering

  • No line-by-line literal translation where the target has a clearer idiom.
  • Error handling is kept, not removed.
  • No new dependencies outside the allowed list.
  • Secrets, keys and paths in the original are replaced by environment variables or parameters.
  • Anything not translatable is marked with a clear comment, not silently dropped.
convert codecode translatorpython to javascriptcode conversionport codejava to python

How to run this

Copy the prompt and paste it into Gemini, then set the aspect ratio to 3:4. No reference photo is needed for this one.

The prompt is written in Markdown with each part under its own heading, which is what the copy action hands over. Change one section at a time, keeping the rest intact, so you can tell which change did the work.

Related prompts

All productivity