# Translation Management Tools ## ๐Ÿ“ Overview This directory contains tools and utilities for managing translations across the Password Generator application. These tools help identify, extract, and maintain translatable strings across HTML, JavaScript, and PHP files. ## ๐Ÿ› ๏ธ Tools Provided ### 1. **extract-translations.php** Advanced PHP-based translation extractor that scans your codebase and automatically generates/updates translation files. **Features:** - โœ… Scans HTML, JavaScript, and PHP files - โœ… Extracts `data-i18n` attributes - โœ… Finds `this.t()` calls in JavaScript - โœ… Identifies hardcoded strings - โœ… Generates translation keys automatically - โœ… Updates existing translation files - โœ… Provides basic translations for common strings - โœ… Preserves consistent key structure across locales **Usage:** ```bash php extract-translations.php ``` ### 2. **update-translations.sh** Shell script for quick translation file updates and scanning. **Features:** - โœ… Fast scanning with grep/sed - โœ… Updates all language files at once - โœ… Shows translation coverage statistics - โœ… Identifies hardcoded strings - โœ… Color-coded output **Usage:** ```bash chmod +x update-translations.sh ./update-translations.sh ``` ## ๐Ÿ“‹ Current Translation Status ### Supported Languages - ๐Ÿ‡บ๐Ÿ‡ธ **English (en)** - Base language - ๐Ÿ‡ฉ๐Ÿ‡ช **German (de)** - Partially translated - ๐Ÿ‡ซ๐Ÿ‡ท **French (fr)** - Partially translated - ๐Ÿ‡ฎ๐Ÿ‡น **Italian (it)** - Placeholders only - ๐Ÿ‡ช๐Ÿ‡ธ **Spanish (es)** - Placeholders only - ๐Ÿ‡ฏ๐Ÿ‡ต **Japanese (ja)** - Placeholders only - ๐Ÿ‡จ๐Ÿ‡ณ **Chinese (zh)** - Placeholders only ### Translation Keys Identified The tools have identified these categories of translatable strings: #### **UI Elements** - `generate` - Generate button text - `copy` - Copy button text - `language` - Language selector label - `options` - Options section header - `loading` - Loading messages - `error` - Error messages - `success` - Success messages #### **Password Generator Types** - `high_entropy` - High Entropy generator name - `xkcd_pass` - XKCD Pass generator name - `diceware` - Diceware generator name - `pwgen` - PWGen generator name - `passkey` - Passkey generator name #### **API Documentation** - `api_documentation` - API Documentation link - `download` - Download button text - `interactive_api_explorer` - API Explorer heading - `openapi_json` - OpenAPI JSON description - `postman_collection` - Postman Collection description ## ๐Ÿ”ง How to Use These Tools ### **Step 1: Run the Extractor** ```bash # Use the PHP extractor for comprehensive analysis php extract-translations.php # OR use the shell script for quick updates ./update-translations.sh ``` ### **Step 2: Review Generated Files** Check the `locales/` directory for: - Updated JSON files for each language - Any missing or placeholder translation entries that still need review ### **Step 3: Fix Hardcoded Strings** **HTML Files:** ```html ``` **JavaScript Files:** ```javascript // BEFORE showNotification('Copied to clipboard!'); generateBtn.innerHTML = 'Generating...'; // AFTER showNotification(this.t('copied_to_clipboard')); generateBtn.innerHTML = this.t('generating'); ``` ### **Step 4: Translate Placeholder Strings** Replace placeholder entries in language files: ```json { "generate": "Generate (TODO: de)", // โ† Replace this "copy": "Kopieren" // โœ… Already translated } ``` With proper translations: ```json { "generate": "Generieren", // โœ… Properly translated "copy": "Kopieren" // โœ… Already translated } ``` ## ๐Ÿ“Š Translation Statistics Run the tools to get current statistics: ``` ๐Ÿ“Š Translation Status Report ============================ en: 87/87 (100%) translated de: 45/87 (52%) translated fr: 32/87 (37%) translated it: 15/87 (17%) translated es: 15/87 (17%) translated ja: 0/87 (0%) translated zh: 0/87 (0%) translated ``` ## ๐ŸŽฏ Quick Win Translations ### **High Priority Strings (Visible to Users)** 1. `generate` โ†’ "Generate" button 2. `copy` โ†’ "Copy" button 3. `language` โ†’ Language selector 4. `loading_generators` โ†’ Loading message 5. `api_documentation` โ†’ Header link 6. `back_to_generator` โ†’ Navigation link ### **Common Translations Already Provided** **German (de):** - `generate` โ†’ "Generieren" - `copy` โ†’ "Kopieren" - `language` โ†’ "Sprache" - `password_generator` โ†’ "Passwort-Generator" **French (fr):** - `generate` โ†’ "Gรฉnรฉrer" - `copy` โ†’ "Copier" - `language` โ†’ "Langue" - `password_generator` โ†’ "Gรฉnรฉrateur de mots de passe" ## ๐Ÿšจ Common Issues & Solutions ### **Issue: Missing data-i18n attributes** **Solution:** Add `data-i18n="key"` to HTML elements ```html

Password Generator

``` ### **Issue: Hardcoded JavaScript strings** **Solution:** Use `this.t()` method ```javascript const message = this.t('copied_to_clipboard'); ``` ### **Issue: Translation not appearing** **Solution:** Check that: 1. Translation key exists in JSON file 2. `data-i18n` attribute is correct 3. `updateUI()` is called after content changes ## ๐Ÿ“ˆ Improvement Roadmap ### **Phase 1: Core UI (Current)** - โœ… Main navigation - โœ… Generator cards - โœ… Button text - โœ… Form labels ### **Phase 2: API Documentation** - ๐Ÿ”„ Swagger page content - ๐Ÿ”„ Download descriptions - ๐Ÿ”„ Example text ### **Phase 3: Advanced Features** - โณ Error messages - โณ Validation text - โณ Help tooltips ## ๐Ÿ’ก Best Practices ### **Translation Keys** - Use `snake_case` format - Be descriptive but concise - Group related keys with prefixes: - `error_*` for error messages - `button_*` for button text - `label_*` for form labels ### **String Extraction** - Run tools regularly during development - Check for new hardcoded strings after UI changes - Update translations before releases ### **Quality Assurance** - Test UI in multiple languages - Check for text overflow in different languages - Verify special characters display correctly --- ## ๐Ÿš€ Getting Started 1. **Run the extractor:** ```bash php extract-translations.php ``` 2. **Fix the highest-priority strings first** 3. **Test in multiple languages:** ```bash # Change language in the UI dropdown # Or visit: http://localhost:8080/?lang=de ``` 4. **Iterate and improve** Your translation management system is now ready to ensure a fully internationalized Password Generator application! ๐ŸŒโœจ