Copilot prompt
Translate Code Between Languages
Convert code from one programming language to another while preserving logic, idioms, and error handling.
Translate this {{source_language}} code to {{target_language}}. ## Source code: ```{{source_language}} {{code}} ``` ### Translation Requirements **1. Preserve Logic** Every branch, loop, and conditional must be preserved. Same inputs must produce the same outputs. Verify edge cases are handled identically. **2. Use Target Language Idioms** Do NOT write {{source_language}}-style code in {{target_language}}. Use {{target_language}}'s standard library where applicable. Prefer idiomatic constructs over literal translations. Examples to apply: - Loops: use {{target_language}}'s preferred iteration style - Error handling: use {{target_language}}'s conventions (try/catch, Result types, etc.) - String manipulation: use built-in methods - Collections: use the appropriate data structure for the context **3. Type System** Apply {{target_language}}'s type system properly. Add type annotations where beneficial. Handle nullable/optional types idiomatically. **4. Dependencies** List any {{source_language}} dependencies used and their {{target_language}} equivalents. If no direct equivalent: suggest the best alternative + note any behavioral differences. **5. Comments** Preserve all meaningful comments (translate the language of the comment too). Add a comment for any translation where the behavior slightly differs. ### Output 1. Translated code 2. Translation notes: any semantic differences or assumptions made 3. Dependencies mapping: source → target equivalents 4. Test cases to verify the translation is correct
Fill in: {{source_language}}, {{target_language}}, {{code}}. In Loopy you fill these in a form and copy the finished prompt in one click.
More refactoring prompts
- CursorAdd TypeScript to Legacy JavaScriptIncrementally migrate a JavaScript codebase to TypeScript without breaking changes, starting with the most critical files.
- CursorOptimize Database QueriesIdentify N+1 queries, add missing indexes, rewrite slow queries, and add performance monitoring to an existing application.
- CursorRefactor with Zero RegressionsStructured refactoring prompt that ensures existing behavior is preserved while improving code quality.

