$
copilot --idea "Polyglot Translator"
→
Rewrite entire projects across languages while preserving logic, tests, and idioms
The Problem
Your team is migrating from Python to Go for performance. Or porting a Java backend to TypeScript for full-stack consistency. Either way, you're staring at 50 files of working code in one language and need equivalent working code in another — preserving business logic, edge cases, and tests.
What You'll Build
A systematic cross-language translation workflow:
- Complete code translation preserving business logic
- Idiomatic output (not just syntax conversion)
- Test translation to verify correctness
- A mapping document showing old ? new file relationships
Step-by-Step Walkthrough
Phase 1: Analysis & Planning
$
"Analyse this Python Flask application and create a translation plan for Go with Gin.
Map each Python file to its Go equivalent.
Identify Python-specific patterns that need different Go approaches:
- Decorators ? middleware
- List comprehensions ? for loops or functional libraries
- Exception handling ? error returns
- Dynamic typing ? static types"
Phase 2: Core Types & Models
Start with the data layer — types and models are the foundation:
$
"Translate all Python dataclasses and Pydantic models in src/models/
to Go structs with JSON tags.
Add validation using go-playground/validator.
Preserve all field constraints and defaults."
Phase 3: Business Logic
$
"Translate src/services/order_service.py to Go.
Preserve ALL business rules exactly.
Use idiomatic Go patterns:
- Return (result, error) instead of raising exceptions
- Use interfaces for dependency injection
- Use context.Context for cancellation
Add comments explaining any non-obvious translation choices."
Phase 4: API Layer
$
"Convert the Flask routes in src/routes/ to Gin handlers.
Map HTTP methods, path parameters, and query parameters exactly.
Translate all middleware (auth, logging, CORS, rate limiting).
Preserve the same API contract — request/response shapes must match."
Phase 5: Test Translation
$
"Translate all pytest tests to Go table-driven tests.
Use testify for assertions.
Translate fixtures to test helper functions.
Ensure the same edge cases are covered.
Run the Go tests and fix any failures."
Phase 6: Verification
$
"Compare the Python and Go implementations:
1. Do all API endpoints match? (method, path, status codes)
2. Are all business rules preserved?
3. Run both test suites — same scenarios should pass
4. Generate an API compatibility report"
Pro Tips
• Use the general-purpose agent — it maintains context across the full translation
• Translate tests BEFORE implementation when possible (TDD across languages)
• Don't try to translate everything at once — go module by module
• Ask for idiomatic code: "A Go developer should read this and think it was written by a Go developer"
• Keep the original code as reference — don't delete until the migration is verified
What You'll Learn
• Deep understanding of language idioms and patterns
• Cross-language API contract preservation
• Testing strategies during migration
• How to use AI for large-scale systematic code transformation