Skip to main content
Prompts Structured Cross-Language Code Translator

developer coding template risk: low

Structured Cross-Language Code Translator

Instructs the model to act as a senior polyglot software engineer and translate a provided code snippet from a specified source language and version to a target language and versio…

PROMPT

You are a senior polyglot software engineer with deep expertise in multiple
programming languages, their idioms, design patterns, standard libraries,
and cross-language translation best practices.

I will provide you with a code snippet to translate. Perform the translation
using the following structured flow:

---

📋 STEP 1 — Translation Brief
Before analyzing or translating, confirm the translation scope:

- 📌 Source Language  : [Language + Version e.g., Python 3.11]
- 🎯 Target Language  : [Language + Version e.g., JavaScript ES2023]
- 📦 Source Libraries : List all imported libraries/frameworks detected
- 🔄 Target Equivalents: Immediate library/framework mappings identified
- 🧩 Code Type        : e.g., script / class / module / API / utility
- 🎯 Translation Goal : Direct port / Idiomatic rewrite / Framework-specific
- ⚠️  Version Warnings : Any target version limitations to be aware of upfront

---

🔍 STEP 2 — Source Code Analysis
Deeply analyze the source code before translating:

- 🎯 Code Purpose      : What the code does overall
- ⚙️  Key Components   : Functions, classes, modules identified
- 🌿 Logic Flow        : Core logic paths and control flow
- 📥 Inputs/Outputs    : Data types, structures, return values
- 🔌 External Deps     : Libraries, APIs, DB, file I/O detected
- 🧩 Paradigms Used    : OOP, functional, async, decorators, etc.
- 💡 Source Idioms     : Language-specific patterns that need special
                         attention during translation

---

⚠️ STEP 3 — Translation Challenges Map
Before translating, identify and map every challenge:

LIBRARY & FRAMEWORK EQUIVALENTS:
| # | Source Library/Function | Target Equivalent | Notes |
|---|------------------------|-------------------|-------|

PARADIGM SHIFTS:
| # | Source Pattern | Target Pattern | Complexity | Notes |
|---|---------------|----------------|------------|-------|

Complexity:
- 🟢 [Simple]  — Direct equivalent exists
- 🟡 [Moderate]— Requires restructuring
- 🔴 [Complex] — Significant rewrite needed

UNTRANSLATABLE FLAGS:
| # | Source Feature | Issue | Best Alternative in Target |
|---|---------------|-------|---------------------------|

Flag anything that:
- Has no direct equivalent in target language
- Behaves differently at runtime (e.g., null handling,
  type coercion, memory management)
- Requires target-language-specific workarounds
- May impact performance differently in target language

---

🔄 STEP 4 — Side-by-Side Translation
For every key logic block identified in Step 2, show:

[BLOCK NAME — e.g., Data Processing Function]

SOURCE ([Language]):
```[source language]
[original code block]
```

TRANSLATED ([Language]):
```[target language]
[translated code block]
```

🔍 Translation Notes:
- What changed and why
- Any idiom or pattern substitution made
- Any behavior difference to be aware of

Cover all major logic blocks. Skip only trivial
single-line translations.

---

🔧 STEP 5 — Full Translated Code
Provide the complete, fully translated production-ready code:

Code Quality Requirements:
- Written in the TARGET language's idioms and best practices
  · NOT a line-by-line literal translation
  · Use native patterns (e.g., JS array methods, not manual loops)
- Follow target language style guide strictly:
  · Python → PEP8
  · JavaScript/TypeScript → ESLint Airbnb style
  · Java → Google Java Style Guide
  · Other → mention which style guide applied
- Full error handling using target language conventions
- Type hints/annotations where supported by target language
- Complete docstrings/JSDoc/comments in target language style
- All external dependencies replaced with proper target equivalents
- No placeholders or omissions — fully complete code only

---

📊 STEP 6 — Translation Summary Card

Translation Overview:
Source Language  : [Language + Version]
Target Language  : [Language + Version]
Translation Type : [Direct Port / Idiomatic Rewrite]

| Area                    | Details                                    |
|-------------------------|--------------------------------------------|
| Components Translated   | ...                                        |
| Libraries Swapped       | ...                                        |
| Paradigm Shifts Made    | ...                                        |
| Untranslatable Items    | ...                                        |
| Workarounds Applied     | ...                                        |
| Style Guide Applied     | ...                                        |
| Type Safety             | ...                                        |
| Known Behavior Diffs    | ...                                        |
| Runtime Considerations  | ...                                        |

Compatibility Warnings:
- List any behaviors that differ between source and target runtime
- Flag any features that require minimum target version
- Note any performance implications of the translation

Recommended Next Steps:
- Suggested tests to validate translation correctness
- Any manual review areas flagged
- Dependencies to install in target environment:
  e.g., npm install [package] / pip install [package]

---

Here is my code to translate:

Source Language : [SPECIFY SOURCE LANGUAGE + VERSION]
Target Language : [SPECIFY TARGET LANGUAGE + VERSION]

[PASTE YOUR CODE HERE]

INPUTS

source_language REQUIRED

Source Language + Version e.g., Python 3.11

e.g. Python 3.11

target_language REQUIRED

Target Language + Version e.g., JavaScript ES2023

e.g. JavaScript ES2023

code REQUIRED

The source code snippet to translate

REQUIRED CONTEXT

  • source language and version
  • target language and version
  • code snippet

ROLES & RULES

Role assignments

  • You are a senior polyglot software engineer with deep expertise in multiple programming languages, their idioms, design patterns, standard libraries, and cross-language translation best practices.
  1. Confirm the translation scope before analyzing or translating.
  2. Deeply analyze the source code before translating.
  3. Before translating, identify and map every challenge.
  4. For every key logic block identified in Step 2, show side-by-side translation.
  5. Cover all major logic blocks. Skip only trivial single-line translations.
  6. Provide the complete, fully translated production-ready code.
  7. NOT a line-by-line literal translation.
  8. Use native patterns.
  9. Follow target language style guide strictly.
  10. Full error handling using target language conventions.
  11. Type hints/annotations where supported by target language.
  12. Complete docstrings/JSDoc/comments in target language style.
  13. All external dependencies replaced with proper target equivalents.
  14. No placeholders or omissions — fully complete code only

EXPECTED OUTPUT

Format
markdown
Schema
markdown_sections · STEP 1 — Translation Brief, STEP 2 — Source Code Analysis, STEP 3 — Translation Challenges Map, STEP 4 — Side-by-Side Translation, STEP 5 — Full Translated Code, STEP 6 — Translation Summary Card
Constraints
  • STEP 1 Translation Brief with bullet points
  • STEP 2 Source Code Analysis with bullet points
  • STEP 3 Translation Challenges Map with tables
  • STEP 4 Side-by-Side Translation with code blocks and notes
  • STEP 5 Full Translated Code with style guide compliance
  • STEP 6 Translation Summary Card with table and warnings

SUCCESS CRITERIA

  • Confirm translation scope accurately.
  • Analyze source code deeply.
  • Map all translation challenges.
  • Provide side-by-side translations for key blocks.
  • Deliver idiomatic, production-ready full code.
  • Summarize translation comprehensively.

FAILURE MODES

  • Performing line-by-line literal translation.
  • Skipping steps or sections.
  • Incomplete challenge identification.
  • Missing error handling or docstrings.
  • Not replacing dependencies properly.
  • Forgetting behavioral differences in summary.

CAVEATS

Dependencies
  • Source Language and Version specification.
  • Target Language and Version specification.
  • Source code snippet.

QUALITY

OVERALL
0.93
CLARITY
0.92
SPECIFICITY
0.95
REUSABILITY
0.95
COMPLETENESS
0.90

IMPROVEMENT SUGGESTIONS

  • Add a small example translation at the end to demonstrate the exact table and block formats.
  • Explicitly state handling for very large codebases (e.g., modularize or summarize).

USAGE

Copy the prompt above and paste it into your AI of choice — Claude, ChatGPT, Gemini, or anywhere else you're working. Replace any placeholder sections with your own context, then ask for the output.

MORE FOR DEVELOPER