Convert code between programming languages while preserving functionality and semantics. Use when: (1) Translating functions, classes, or modules between languages (Python, JavaScript/TypeScript, Java, Go, Rust, C/C++), (2) Migrating entire projects to a different language, (3) Need idiomatic translation that follows target language conventions, (4) Converting between different paradigms (OOP to functional, etc.), (5) Porting legacy code to modern languages. Provides language-specific patterns, idiomatic translation guides, and project migration strategies.
npx skills add https://github.com/ArabelaTso/Skills-4-SE --skill code-translation
Convert code between programming languages while preserving functionality, adapting to target language idioms and best practices.
Understand what the code does:
Direct Translation: Literal conversion maintaining structure
Idiomatic Translation: Adapt to target language patterns
Recommended: Start with direct translation, then refine to idiomatic.
Perform the translation following language patterns and conventions.
Ensure translated code behaves identically to source:
Source (Python)
def calculate_total(items):
"""Calculate total price with tax."""
subtotal = sum(item['price'] * item['quantity'] for item in items)
tax = subtotal * 0.08
return subtotal + tax
# Usage
items = [
{'name': 'Widget', 'price': 10.0, 'quantity': 2},
{'name': 'Gadget', 'price': 15.0, 'quantity': 1}
]
total = calculate_total(items)
Target (JavaScript)
function calculateTotal(items) {
// Calculate total price with tax
const subtotal = items.reduce(
(sum, item) => sum + item.price * item.quantity,
0
);
const tax = subtotal * 0.08;
return subtotal + tax;
}
// Usage
const items = [
{ name: 'Widget', price: 10.0, quantity: 2 },
{ name: 'Gadget', price: 15.0, quantity: 1 }
];
const total = calculateTotal(items);
Source (JavaScript)
async function fetchUserData(userId) {
try {
const response = await fetch(`/api/users/${userId}`);
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
return await response.json();
} catch (error) {
console.error(`Failed to fetch user: ${error.message}`);
return null;
}
}
Target (Python)
import aiohttp
import logging
async def fetch_user_data(user_id: int) -> dict | None:
"""Fetch user data from API."""
try:
async with aiohttp.ClientSession() as session:
async with session.get(f'/api/users/{user_id}') as response:
if not response.ok:
raise ValueError(f'HTTP {response.status}')
return await response.json()
except Exception as e:
logging.error(f'Failed to fetch user: {e}')
return None
Source (Java)
public class UserService {
private final UserRepository repository;
public UserService(UserRepository repository) {
this.repository = repository;
}
public Optional<User> findById(Long id) {
return repository.findById(id);
}
public List<User> findAll() {
return repository.findAll();
}
}
Target (Go)
type UserService struct {
repository UserRepository
}
func NewUserService(repository UserRepository) *UserService {
return &UserService{repository: repository}
}
func (s *UserService) FindById(id int64) (*User, error) {
return s.repository.FindById(id)
}
func (s *UserService) FindAll() ([]User, error) {
return s.repository.FindAll()
}
Lists/Arrays
# Python
numbers = [1, 2, 3]
numbers.append(4)
// JavaScript
const numbers = [1, 2, 3];
numbers.push(4);
// Go
numbers := []int{1, 2, 3}
numbers = append(numbers, 4)
Dictionaries/Maps
# Python
user = {"name": "Alice", "age": 30}
// JavaScript
const user = { name: "Alice", age: 30 };
// Go
user := map[string]interface{}{
"name": "Alice",
"age": 30,
}
Exceptions → Error Returns
# Python
def divide(a, b):
if b == 0:
raise ValueError("Cannot divide by zero")
return a / b
// Go
func divide(a, b float64) (float64, error) {
if b == 0 {
return 0, errors.New("cannot divide by zero")
}
return a / b, nil
}
Error Returns → Exceptions
// Go
result, err := divide(10, 0)
if err != nil {
return err
}
# Python
try:
result = divide(10, 0)
except ValueError as e:
print(f"Error: {e}")
Python asyncio → JavaScript async/await
# Python
async def fetch_all(urls):
tasks = [fetch(url) for url in urls]
return await asyncio.gather(*tasks)
// JavaScript
async function fetchAll(urls) {
const promises = urls.map(url => fetch(url));
return await Promise.all(promises);
}
JavaScript Promises → Go Goroutines
// JavaScript
const results = await Promise.all([
fetchUser(1),
fetchUser(2),
fetchUser(3)
]);
// Go
var wg sync.WaitGroup
results := make([]*User, 3)
for i := 1; i <= 3; i++ {
wg.Add(1)
go func(id int) {
defer wg.Done()
results[id-1] = fetchUser(id)
}(i)
}
wg.Wait()
Is this a complete project migration?
├─ Yes → See [project_migration.md](references/project_migration.md)
│ Follow 8-phase migration process
│
└─ No → Is this a function/class/module?
│
├─ Single function
│ ├─ Simple logic? → Direct translation
│ └─ Complex logic? → Idiomatic translation
│
├─ Class with methods
│ ├─ Does target language have classes?
│ │ ├─ Yes → Translate class structure
│ │ └─ No → Convert to module/functions
│
└─ Full module
└─ Translate file by file
Consider dependencies first
See idiomatic_guide.md for:
See language_patterns.md for detailed patterns:
See project_migration.md for:
Focus on what the code does, not how it's written:
# Python (imperative)
total = 0
for item in items:
total += item.price
// JavaScript (functional - different structure, same behavior)
const total = items.reduce((sum, item) => sum + item.price, 0);
Don't fight the language - embrace its strengths:
# Python - use list comprehensions
squares = [x**2 for x in range(10)]
# Not: Java-style loop
squares = []
for x in range(10):
squares.append(x**2)
Add type hints/annotations in statically typed languages:
# Python source (dynamic)
def greet(name):
return f"Hello, {name}"
// TypeScript (add types)
function greet(name: string): string {
return `Hello, ${name}`;
}
Map to equivalent libraries or implement abstractions:
# Python using requests
import requests
response = requests.get(url)
data = response.json()
// JavaScript using fetch
const response = await fetch(url);
const data = await response.json();
Verify translated code behaves identically:
# Port tests alongside code
def test_calculate_total():
items = [{"price": 10, "quantity": 2}]
assert calculate_total(items) == 21.6 # 20 + 8% tax
// Same test in target language
test('calculateTotal', () => {
const items = [{ price: 10, quantity: 2 }];
expect(calculateTotal(items)).toBe(21.6);
});
❌ Translating line-by-line without adapting
✅ Adapting to target language patterns
❌ Using any/interface{}/Object everywhere
✅ Proper typing and error handling
❌ Translating implementation details
✅ Translating behavior and intent
❌ Assuming same behavior for edge cases
✅ Testing boundary conditions
❌ Ignoring performance characteristics
✅ Profiling and optimizing for target language
Python Source
class Calculator:
"""Simple calculator with memory."""
def __init__(self):
self.memory = 0
def add(self, a: float, b: float) -> float:
"""Add two numbers."""
result = a + b
self.memory = result
return result
def recall(self) -> float:
"""Recall last result."""
return self.memory
def clear(self):
"""Clear memory."""
self.memory = 0
TypeScript Translation
/**
* Simple calculator with memory.
*/
class Calculator {
private memory: number = 0;
/**
* Add two numbers.
*/
add(a: number, b: number): number {
const result = a + b;
this.memory = result;
return result;
}
/**
* Recall last result.
*/
recall(): number {
return this.memory;
}
/**
* Clear memory.
*/
clear(): void {
this.memory = 0;
}
}
Go Translation (Idiomatic)
// Calculator is a simple calculator with memory.
type Calculator struct {
memory float64
}
// NewCalculator creates a new calculator.
func NewCalculator() *Calculator {
return &Calculator{memory: 0}
}
// Add two numbers and store result in memory.
func (c *Calculator) Add(a, b float64) float64 {
result := a + b
c.memory = result
return result
}
// Recall returns the last result.
func (c *Calculator) Recall() float64 {
return c.memory
}
// Clear resets the memory to zero.
func (c *Calculator) Clear() {
c.memory = 0
}
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
Automatically creates user-facing changelogs from git commits by analyzing commit history, categorizing changes, and transforming technical commits into clear, customer-friendly release notes. Turns hours of manual changelog writing into minutes of automated generation.
Use when implementation is complete, all tests pass, and you need to decide how to integrate the work - guides completion of development work by presenting structured options for merge, PR, or cleanup
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
React Native and Expo best practices for building performant mobile apps. Use when building React Native components, optimizing list performance, implementing animations, or working with native modules. Triggers on tasks involving React Native, Expo, mobile performance, or native platform APIs.
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.
Next.js best practices - file conventions, RSC boundaries, data patterns, async APIs, metadata, error handling, route handlers, image/font optimization, bundling
Use when starting feature work that needs isolation from current workspace or before executing implementation plans - creates isolated git worktrees with smart directory selection and safety verification
Take arabelatso/code-translation from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.