Convert Code Between Programming Languages with AI
A prompt to convert code from one programming language to another while respecting the conventions, native idioms and best practices of the target language.
Paste in your AI
Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.
Tu es un développeur senior expert en [LANGAGE_SOURCE] et en [LANGAGE_CIBLE]. Je vais te fournir du code écrit en [LANGAGE_SOURCE] et tu dois le convertir en [LANGAGE_CIBLE] en respectant les règles suivantes :
- Préserver la logique métier : le comportement fonctionnel doit être strictement identique.
- Adopter les conventions du langage cible : nommage des variables (camelCase, snake_case, etc.), structure des fichiers, organisation du code selon les standards de [LANGAGE_CIBLE].
- Utiliser les idiomes natifs : remplacer les patterns du langage source par leurs équivalents idiomatiques dans le langage cible (ex : list comprehension en Python, streams en Java, pattern matching en Rust).
- Gérer les dépendances : si le code source utilise des bibliothèques, propose les équivalents les plus populaires et maintenus dans l'écosystème de [LANGAGE_CIBLE].
- Typage et gestion d'erreurs : adapte le système de types et la gestion des erreurs aux conventions du langage cible.
- Commentaires : traduis les commentaires en français et ajoute des annotations là où la conversion implique un choix d'implémentation différent.
Pour chaque conversion, fournis :
- Le code converti complet et fonctionnel
- Un tableau récapitulatif des correspondances clés (structures, fonctions, types) entre les deux langages
- Les points d'attention ou différences de comportement potentielles
- Les dépendances à installer dans le langage cible
Voici le code à convertir :
[CODE_A_CONVERTIR]
Personalize this prompt with Léa
Answer 3 questions and Léa tailors the prompt to your situation.
Why this prompt works
<p>This prompt transforms the AI into an expert code translator that goes beyond word-for-word syntactic conversion. By specifying the <strong>source language</strong> and <strong>target language</strong>, you get an idiomatic rewrite that respects the conventions and best practices of each ecosystem.</p><p>The six rules govern conversion quality: preserving business logic, adopting naming conventions, using native patterns, replacing libraries with their equivalents, adapting typing and translating comments. The correspondence summary table helps you <strong>understand the conversion choices</strong> and build skills in the new language.</p><p>For better results, provide complete code rather than isolated snippets, and specify the target language version if it matters (e.g., Python 3.12, Java 21, TypeScript 5). Feel free to add context about the intended use: <strong>CLI script, web API, shared library</strong>, etc.</p>
Use Cases
Expected Output
Complete code converted to the target language with idiomatic conventions, a correspondence table between the two languages, notes on behavioral differences and a list of required dependencies.
Learn more
Check the full skill on Prompt Guide to master this technique from A to Z.
View on Prompt GuideComments
- LéaAI
Pour éviter des itérations inutiles, ajoutez dans le prompt un niveau de “fidélité” : « conversion littérale » (structure identique, juste la syntaxe) ou « conversion idiomatique » (réécriture native). Cela évite que l’IA oscille entre les deux.
📬 Get new prompts every week
Join our newsletter and never miss a prompt.
Similar Prompts
Implement property-based testing
Add property-based tests
GitHub Copilot Prompt for Generating JavaScript Code
GitHub Copilot, the AI-powered programming assistant developed by GitHub and OpenAI, has transformed the way developers write JavaScript code. By leveraging billions of lines of open-source code, Copilot can generate complete functions, classes, modules, and even entire architectures from simple natural language descriptions. To get the most out of this tool, mastering the art of prompt engineering for code generation is essential. A well-structured prompt produces clean, performant JavaScript code that adheres to modern best practices (ES2024+, implicit typing, error handling, modularity). In this guide, we offer optimized prompts for GitHub Copilot that will help you generate professional-grade JavaScript code, whether you're developing a REST API, a frontend component, a utility script, or complex business logic. Each prompt is designed to provide sufficient context to Copilot while allowing the flexibility needed for relevant and project-adapted generation.
Automatically Generate Unit Tests with AI
Automatically generate an exhaustive unit test suite covering nominal cases, edge cases, and error cases for any source code.
Write a network security audit
Audit network security