3.4 KiB
3.4 KiB
Translation Automation System
This directory contains the automated translation system for the Front-end Developer Interview Questions repository.
Overview
The translation system automatically converts English questions from src/questions/ into translated versions for each target language in src/translations/.
Files
translate.js- Main translation scripttranslation-config.json- Configuration for languages and AI settings
Usage
Prerequisites
- Set up OpenAI API key (optional - falls back to mock translations if not available):
export OPENAI_API_KEY="your-api-key-here"
Running Translations
Translate all languages:
npm run translate:all
Translate a specific language:
npm run translate spanish
# or
node scripts/translate.js spanish
Available languages:
test-lang- Test language for developmentspanish- Spanish translationfrench- French translationchinese- Chinese translation
Adding New Languages
- Add language configuration to
translation-config.json:
{
"languages": {
"your-language": {
"title": "Your Language Title",
"lang": "language-code",
"rtl": false,
"sections": {
"general": "General Questions Translation",
"html": "HTML Questions Translation",
// ... etc
}
}
}
}
- Create the target directory:
mkdir -p src/translations/your-language
- Run the translation:
npm run translate your-language
How It Works
- Question Extraction: Reads all English question files from
src/questions/ - AI Translation: Uses OpenAI GPT-4 to translate questions while preserving format
- File Generation: Creates translated README.md files using the template structure
- Format Preservation: Maintains markdown formatting, code snippets, and navigation
Question Formats Supported
- Bullet Point Questions: Standard
* Question textformat - Coding Questions:
Question: What is...format with code blocks - Nested Questions: Indented sub-questions with
* Sub-question
Configuration
Language Configuration
Each language needs:
title: Translated page titlelang: Language code (e.g., 'es', 'fr', 'zh')rtl: Boolean for right-to-left languagessections: Translated section headers
AI Configuration
provider: Currently supports "openai"model: AI model to use (default: "gpt-4")systemPrompt: Instructions for the AI translator
Development
Testing
Use the test-lang language for development and testing:
npm run translate test-lang
Mock Translations
When OpenAI API is not available, the system falls back to mock translations that prefix questions with [LANGUAGE] for testing.
Integration with Build Process
The translation system can be integrated into CI/CD workflows to automatically update translations when English questions change.
GitHub Actions Example:
- name: Update Translations
run: |
export OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}
npm run translate:all
Future Enhancements
- Support for additional AI providers (Azure OpenAI, Google Translate, etc.)
- Incremental translations (only update changed questions)
- Translation quality validation
- Support for more complex markdown structures
- Translation memory and consistency checking