mcpbeat Sign in

Module Level Code Translator Agent Skill

Translate source code between programming languages at function, class, and module levels while preserving behavior and generating verification tests. Use when translating code from one language to another (e.g., "translate this Python module to JavaScript", "convert this Java class to C#", "port this code to Go and generate tests"), migrating codebases between languages, or creating equivalent implementations across different technology stacks. Handles idiom adaptation, standard library mappings, and test generation.

5k tokens
context cost
the whole folder, loaded on every use
8
files
ships runnable scripts
0
copies elsewhere
how many repositories repackaged it
141
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/ArabelaTso/Skills-4-SE --skill module-level-code-translator

The instruction itself

18 sections, as written by the author

Module-Level Code Translator

Translate source code between programming languages while preserving behavior, adapting idioms, and generating verification tests.

Translation Workflow

Follow this sequential process for code translation:

1. Analyze Source Code

Before translating, thoroughly understand the source code:

  • Identify scope: Determine if translating functions, classes, or entire modules
  • Map dependencies: List all imports, external libraries, and dependencies
  • Understand behavior: Identify core logic, algorithms, and expected behavior
  • Note language-specific features: Identify features that require special handling (decorators, generators, async/await, etc.)
  • Extract test cases: If existing tests are available, analyze them to understand expected behavior

2. Plan Translation Strategy

Create a translation plan before writing code:

  • Map standard libraries: Identify equivalent libraries in target language (see references/stdlib_mappings.md)
  • Adapt idioms: Plan how to translate language-specific patterns (see references/language_mappings.md)
  • Handle type systems: Plan type annotations/declarations if moving between typed/untyped languages
  • Identify testing framework: Choose appropriate testing framework for target language (see references/testing_frameworks.md)
  • List transformations: Document major transformations needed (e.g., class → struct, decorator → annotation)

3. Translate Code

Implement the translation following target language conventions:

Core principles:

  • Preserve original behavior exactly
  • Follow target language idioms and conventions
  • Maintain code structure when possible (functions → functions, classes → classes)
  • Adapt patterns that don't translate directly (e.g., Python decorators → Java annotations)
  • Add appropriate error handling for target language
  • Include necessary imports and dependencies

Common transformations:

Python → JavaScript:

  • Classes: Keep class structure, adapt __init__ to constructor
  • List comprehensions: Convert to .map(), .filter(), .reduce()
  • Decorators: Convert to higher-order functions or use libraries
  • Type hints: Convert to TypeScript or JSDoc comments

Python → Java:

  • Functions: Convert to static methods or instance methods in classes
  • Dynamic typing: Add explicit type declarations
  • Duck typing: Use interfaces or abstract classes
  • List/dict operations: Use Collections framework

Python → Go:

  • Classes: Convert to structs with methods
  • Exceptions: Convert to error return values
  • Dynamic features: Use interfaces for polymorphism
  • List comprehensions: Use explicit loops

Java → C#:

  • Naming: Convert PascalCase for methods
  • Properties: Use C# property syntax instead of getters/setters
  • Collections: Map to .NET collections
  • Annotations: Convert to C# attributes

4. Generate Tests

Create comprehensive tests to verify translation correctness:

Test generation approach:

  • Use appropriate test template from assets/ directory
  • Port existing tests if available in source code
  • Create new tests covering:
  • Basic functionality for each function/method
  • Edge cases (empty inputs, null values, boundary conditions)
  • Error handling and exceptions
  • Integration between components

Test equivalence:

  • Ensure tests verify the same behavior as original code
  • Use equivalent assertions (see references/testing_frameworks.md)
  • Maintain test structure and organization
  • Add setup/teardown as needed for target framework

5. Create Translation Summary

Document the translation with a summary including:

Mappings:

  • List of source → target function/class/module mappings
  • Standard library equivalences used
  • External dependencies and their target equivalents

Transformations:

  • Major structural changes (e.g., decorator → annotation)
  • Idiom adaptations (e.g., list comprehension → map/filter)
  • Type system changes (dynamic → static typing)

Verification notes:

  • Test coverage summary
  • Known limitations or differences
  • Manual verification steps if needed

Output Format

Provide the translation in this structure:

## Translated Code

[Target language code with appropriate file structure]

## Tests

[Test code using target language testing framework]

## Translation Summary

### Mappings
- SourceClass → TargetClass
- source_function() → targetFunction()
- source_module → target.package

### Standard Library Equivalences
- source.lib.function → target.lib.function

### Transformations
- [Description of major transformations]

### Verification
- [Test coverage and verification notes]

Language-Specific Considerations

Python → JavaScript/TypeScript

  • Convert snake_case to camelCase
  • Handle async/await (similar syntax)
  • Map list/dict operations to array/object methods
  • Consider using TypeScript for type safety

Python → Java

  • Add explicit type declarations throughout
  • Convert modules to packages with proper structure
  • Use appropriate Java collections (ArrayList, HashMap, etc.)
  • Handle checked exceptions

Python → Go

  • Convert classes to structs with receiver methods
  • Replace exceptions with error return values
  • Use goroutines for concurrency (if applicable)
  • Follow Go naming conventions (exported vs unexported)

Java → C#

  • Convert naming conventions (PascalCase methods)
  • Use C# properties instead of getters/setters
  • Map Java collections to .NET equivalents
  • Convert annotations to attributes

JavaScript → Python

  • Convert camelCase to snake_case
  • Handle promises/async with Python async/await
  • Map array methods to list comprehensions or loops
  • Add type hints if using modern Python

Resources

references/

  • language_mappings.md: Common idiom mappings between languages
  • stdlib_mappings.md: Standard library equivalences across languages
  • testing_frameworks.md: Testing framework mappings and patterns

assets/

Test templates for common target languages:

  • test_template_python.py: pytest template
  • test_template_javascript.js: Jest template
  • test_template_java.java: JUnit 5 template
  • test_template_go.go: Go testing template

Use these templates as starting points for generated tests.

Best Practices

  • Preserve behavior first: Correctness is more important than idiomatic code
  • Follow target conventions: Use target language's naming, structure, and patterns
  • Test thoroughly: Generate comprehensive tests to verify equivalence
  • Document differences: Note any behavioral differences or limitations
  • Handle edge cases: Ensure edge cases are properly translated
  • Consider performance: Be aware of performance implications of translations
  • Use appropriate types: Leverage target language's type system effectively
  • Maintain readability: Keep code readable and maintainable in target language

Other skills for the same job

different authors, same section of the catalogue
MCP Builder
by anthropics
vendor ×13

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).

30k tokens scripts
Changelog Generator
by frostant
×9

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.

774 tokens
Finishing A Development Branch
by ZhanlinCui
×7

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

1k tokens
MCP Builder
by JayZeeDesign
×7

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).

37k tokens scripts
Vercel React Native Skills
by vercel-labs
vendor ×6

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.

39k tokens
Vercel React Best Practices
by ratacat
×5

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.

34k tokens
Next Best Practices
by vercel-labs
vendor ×4

Next.js best practices - file conventions, RSC boundaries, data patterns, async APIs, metadata, error handling, route handlers, image/font optimization, bundling

20k tokens
Using Git Worktrees
by ZhanlinCui
×4

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

1k tokens

How to use it

Copy the folder

Take arabelatso/module-level-code-translator from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

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.