Human Languages in Source Code: Auto-Translation for Localized Instruction

Chris Piech, Sami Abu-El-Haija

This paper, presented at a 2019 conference, tackles a fundamental but often overlooked barrier in computer science: the English language. While logic is universal, the "human language" of source code—variable names, method identifiers, and comments—is overwhelmingly English, creating a "double cognitive load" for billions of non-native speakers.

TL;DR

Researchers from Stanford and USC introduce CodeInternational, the first tool designed to translate source code (identifiers and comments) across 100+ human languages while preserving code functionality. By combining a large-scale study of 2.9 million GitHub repositories with a specialized translation pipeline, they demonstrate that localized instruction can significantly lower the barrier to entry for global CS education.

What Problem Does This Paper Address?

Most programming languages (Java, Python, etc.) use English keywords, and the vast majority of open-source libraries and educational materials are written in English. For a student in Brazil or China, learning to code means simultaneously learning a foreign language.

Existing translation tools like Google Translate fail when applied directly to code because they don't understand programming syntax. They might translate a camelCase variable like getFavoriteNumber into a nonsensical string or break the code's structure entirely. This paper seeks to automate the "human-language" translation of code to make learning more accessible and to understand how non-English speakers currently navigate the English-dominated world of GitHub.

Methods

The authors developed a two-part approach: a data-driven analysis and a translation tool.

  1. GitHub Mining: They analyzed 2.9 million Java repositories to identify patterns in how non-English speakers use identifiers and comments. They used Google Language Detect on commit messages to estimate a user's preferred language.
  2. The CodeInternational Pipeline:
    • Tokenization: The tool parses code (using javalang for Java and parser for Python) to distinguish between "Immutable" tokens (keywords like while or void) and "Target" tokens (user-defined variable and function names).
  3. Identifier Segmentation: It breaks down naming conventions (e.g., camelCase or snake_case) into individual words before translation.
  4. Verb Prior: To ensure method names make sense, the tool applies a "verb prior," forcing the first word of a method to be translated as a verb (e.g., translating move() to the Spanish moverse rather than the noun movimiento).
  5. Structure Preservation: It strips text from comments, translates it, and then reformats it back into the original Javadoc or block comment structure.

Datasets

  • GitHub Java Repositories: A massive dataset of 2.9 million repositories and 1.1 million unique users used to study real-world non-English coding patterns.
  • Evaluation Set: 1,000 randomly selected single-file Java projects from GitHub used to test the translation tool's accuracy and "compilability."
  • Karel the Robot: A popular introductory programming curriculum (the "Karel reader") which the authors translated into 100+ languages as a proof-of-concept.

Key Insights and Ideas

  • The "Survivorship Bias" of GitHub: Only 12.7% of GitHub users write commit messages in non-English languages. The authors suggest this is a form of survivorship bias—those who can't navigate the English-centric platform simply never join.
  • Script vs. Transliteration: There is a stark divide in how different cultures code. Users of Latin-based scripts (Spanish, German) often use their native language for identifiers. However, users of non-Latin scripts (Chinese, Russian, Korean) almost exclusively use English for identifiers while reserving their native script for comments.
  • The RTL Barrier: Right-to-Left (RTL) languages like Arabic and Hebrew are almost entirely absent from code identifiers (found in only 0.6% of repos from those regions), indicating a massive technical and cultural barrier for these speakers.

Key Results

  • Robustness: 100% of the 1,000 translated GitHub projects maintained their ability to compile after translation.
  • Translation Accuracy: 91% of identifiers were successfully translated. The remaining 9% failed primarily due to non-standard abbreviations (e.g., frac instead of fraction).
  • Educational Impact: The authors localized the "Karel the Robot" textbook into 100+ languages. This interactive reader has already been used by over 3,000 people across 50 countries, with high engagement levels (average session durations of ~10 minutes).

Limitations and Future Work

  • Identifier Consistency: A current limitation is ensuring that a specific term (like "height") is translated consistently across different identifiers (e.g., getHeight and setHeight). Modern neural machine translation doesn't always guarantee this.
  • Abbreviations: The tool struggles with short-hand variable names common in professional code.
  • Tooling Integration: The authors call for future work to integrate these APIs directly into popular IDEs like VS Code or Eclipse to allow for real-time, side-by-side translation for students.
  • Cost: The reliance on the Google Translate API incurs a cost ($1 per 50,000 characters), which could be a barrier for large-scale free deployment.

Summary updated

BibTeX
@inproceedings{piech2020human,
  author = {Chris Piech and Sami Abu-El-Haija},
  title = {{Human Languages in Source Code: Auto-Translation for Localized Instruction}},
  booktitle = {L@S},
  year = {2020},
  doi = {10.1145/3386527.3405916},
}
Figure