|
| 1 | +# Red Hat Developer Hub - Internationalization (i18n) Scripts |
| 2 | + |
| 3 | +This directory contains scripts for managing translation workflows with **TMS (Translation Management System)** for the Red Hat Developer Hub project. |
| 4 | + |
| 5 | +## 📁 Repository Structure |
| 6 | + |
| 7 | +This i18n workflow handles translations for: |
| 8 | + |
| 9 | +``` |
| 10 | +rhdh/scripts/i18n-scripts/ # Handles rhdh + community-plugins |
| 11 | +``` |
| 12 | + |
| 13 | +### **Why This Approach?** |
| 14 | + |
| 15 | +- **Post-processing**: Easy JSON → TypeScript conversion workflow |
| 16 | +- **Comparison workflow**: Simple to compare downloaded translations with existing ones |
| 17 | +- **Clean organization**: Repository-specific translations stay organized |
| 18 | +- **Flexible deployment**: Deploy to appropriate locations in your projects |
| 19 | + |
| 20 | +## 🚀 Quick Start |
| 21 | + |
| 22 | +```bash |
| 23 | +# Upload English source strings to TMS |
| 24 | +yarn i18n-upload |
| 25 | + |
| 26 | +# Download completed translations |
| 27 | +yarn i18n-download |
| 28 | + |
| 29 | +# Get help |
| 30 | +yarn i18n-upload:help |
| 31 | +yarn i18n-download:help |
| 32 | +``` |
| 33 | + |
| 34 | +## 📋 Configuration |
| 35 | + |
| 36 | +### **Environment Setup** |
| 37 | + |
| 38 | +First, configure your TMS credentials: |
| 39 | + |
| 40 | +```bash |
| 41 | +# Add to ~/.bashrc or ~/.zshrc |
| 42 | +export MEMSOURCE_USERNAME="your-username" |
| 43 | +export MEMSOURCE_TOKEN="your-api-token" |
| 44 | + |
| 45 | +# Source TMS CLI configuration |
| 46 | +source ~/.memsourcerc # Contains TMS connection details |
| 47 | +``` |
| 48 | + |
| 49 | +### **Script Configuration** |
| 50 | + |
| 51 | +Edit [`i18n.config.sh`](./i18n.config.sh) to customize: |
| 52 | + |
| 53 | +```bash |
| 54 | +# Release version |
| 55 | +RHDH_RELEASE="${RHDH_RELEASE:-1.8}" |
| 56 | + |
| 57 | +# TMS Project ID |
| 58 | +TMS_PROJECT_ID="${TMS_PROJECT_ID:-33299484}" |
| 59 | + |
| 60 | +# Target languages for download |
| 61 | +DOWNLOAD_LANGS="${DOWNLOAD_LANGS:-fr}" |
| 62 | + |
| 63 | +# File organization strategy |
| 64 | +ORGANIZE_BY="${ORGANIZE_BY:-by-language}" # community-plugins/plugin-name/, rhdh/ flat |
| 65 | +``` |
| 66 | + |
| 67 | +## 🔄 Workflow Overview |
| 68 | + |
| 69 | +### **1. Upload Workflow** |
| 70 | + |
| 71 | +```mermaid |
| 72 | +graph LR |
| 73 | + A[ref.ts files] --> B[Extract Messages] |
| 74 | + B --> C[Generate JSON] |
| 75 | + C --> D[Validate JSON] |
| 76 | + D --> E[Upload to TMS] |
| 77 | + E --> F[Cache Uploaded] |
| 78 | +``` |
| 79 | + |
| 80 | +**Processes:** |
| 81 | +- **rhdh repository**: TypeScript translation references |
| 82 | +- **community-plugins repository**: Plugin translation files |
| 83 | +- **Generates**: English JSON files for TMS upload |
| 84 | +- **Caching**: Prevents re-uploading unchanged files |
| 85 | + |
| 86 | +### **2. Download Workflow** |
| 87 | + |
| 88 | +```mermaid |
| 89 | +graph LR |
| 90 | + A[TMS Jobs] --> B[Filter Latest] |
| 91 | + B --> C[Download JSON] |
| 92 | + C --> D[Organize Files] |
| 93 | + D --> E[Cache Jobs] |
| 94 | +``` |
| 95 | + |
| 96 | +**Processes:** |
| 97 | +- **Latest-only**: Automatically selects newest translation for each file |
| 98 | +- **Organization**: Groups by repository and plugin |
| 99 | +- **Caching**: Prevents re-downloading completed jobs |
| 100 | + |
| 101 | +## 📂 File Organization |
| 102 | + |
| 103 | +### **Upload (Staging)** |
| 104 | + |
| 105 | +``` |
| 106 | +rhdh/ui-i18n/1.8/ |
| 107 | +├── rhdh__packages__app__src__translations__ref-en.json |
| 108 | +├── rhdh__packages__backend__src__translations__ref-en.json |
| 109 | +└── community-plugins__workspaces__bulk-import__plugins__bulk-import__src__translations__ref-en.json |
| 110 | +``` |
| 111 | + |
| 112 | +### **Download (Organized)** |
| 113 | + |
| 114 | +``` |
| 115 | +rhdh/ui-i18n-downloads/1.8/ |
| 116 | +├── community-plugins/ |
| 117 | +│ ├── bulk-import/ |
| 118 | +│ │ └── community-plugins__workspaces__bulk-import__...ref-en-fr-C.json |
| 119 | +│ └── lighthouse/ |
| 120 | +│ └── community-plugins__workspaces__lighthouse__...ref-en-es-C.json |
| 121 | +└── rhdh/ |
| 122 | + ├── rhdh__packages__app__...ref-en-fr-C.json |
| 123 | + └── rhdh__packages__backend__...ref-en-de-C.json |
| 124 | +``` |
| 125 | + |
| 126 | +## 🛠️ Available Scripts |
| 127 | + |
| 128 | +### **Upload Scripts** |
| 129 | + |
| 130 | +#### `collect-and-upload.sh` - Main Upload Orchestrator |
| 131 | + |
| 132 | +```bash |
| 133 | +# Basic usage |
| 134 | +./collect-and-upload.sh |
| 135 | + |
| 136 | +# With overrides |
| 137 | +./collect-and-upload.sh -r 1.9 -s 3280 -t 'fr,es,de' |
| 138 | + |
| 139 | +# Environment variable + cleanup |
| 140 | +CLEAN_AFTER_UPLOAD=1 ./collect-and-upload.sh |
| 141 | +``` |
| 142 | + |
| 143 | +**Options:** |
| 144 | +- `-r, --release VERSION`: RHDH release version |
| 145 | +- `-s, --sprint NUMBER`: Sprint number for TMS |
| 146 | +- `-p, --project-id ID`: TMS project ID override |
| 147 | +- `-t, --target-langs LANGS`: Target languages (comma-separated) |
| 148 | + |
| 149 | +#### `memsource-upload.sh` - TMS Upload Wrapper |
| 150 | + |
| 151 | +Lower-level script called by the main orchestrator. |
| 152 | + |
| 153 | +### **Download Scripts** |
| 154 | + |
| 155 | +#### `collect-and-download.sh` - Main Download Orchestrator |
| 156 | + |
| 157 | +```bash |
| 158 | +# Download all completed French translations |
| 159 | +./collect-and-download.sh |
| 160 | + |
| 161 | +# Multiple languages |
| 162 | +./collect-and-download.sh --languages fr,es,de,ja |
| 163 | + |
| 164 | +# Specific job ID |
| 165 | +./collect-and-download.sh pMeeU5JfqcECe9DAqP8AA3 |
| 166 | + |
| 167 | +# Dry run (preview) |
| 168 | +./collect-and-download.sh --dry-run |
| 169 | +``` |
| 170 | + |
| 171 | +**Options:** |
| 172 | +- `--project-id ID`: Override TMS project ID |
| 173 | +- `--languages LANGS`: Target languages (comma-separated) |
| 174 | +- `--status STATUS`: Job status filter (COMPLETED, NEW, etc.) |
| 175 | +- `--organize-by TYPE`: File organization (`flat`, `by-language`) |
| 176 | +- `--output-dir DIR`: Custom output directory |
| 177 | +- `--dry-run`: Preview mode (no actual downloads) |
| 178 | +- `--clean-before`: Remove existing download directory |
| 179 | + |
| 180 | +#### `memsource-download.sh` - TMS Download Wrapper |
| 181 | + |
| 182 | +Lower-level script for TMS CLI operations. |
| 183 | + |
| 184 | +### **Utility Scripts** |
| 185 | + |
| 186 | +#### `extract-ts-messages.mjs` - TypeScript Message Extractor |
| 187 | + |
| 188 | +Extracts i18n messages from TypeScript `ref.ts` files and converts them to JSON format for TMS upload. |
| 189 | + |
| 190 | +## 🎯 Use Cases |
| 191 | + |
| 192 | +### **1. Regular Translation Cycle** |
| 193 | + |
| 194 | +```bash |
| 195 | +# 1. Upload new/updated source strings |
| 196 | +yarn i18n-upload |
| 197 | + |
| 198 | +# 2. Wait for translators to complete work in TMS |
| 199 | +# ... |
| 200 | + |
| 201 | +# 3. Download completed translations |
| 202 | +yarn i18n-download |
| 203 | + |
| 204 | +# 4. Process downloaded JSON files |
| 205 | +# - Convert to TypeScript (.ts files) |
| 206 | +# - Compare with existing translations |
| 207 | +# - Replace inaccurate/outdated ones |
| 208 | +``` |
| 209 | + |
| 210 | +### **2. Specific Language Release** |
| 211 | + |
| 212 | +```bash |
| 213 | +# Download only specific languages |
| 214 | +yarn i18n-download --languages fr,es,de |
| 215 | + |
| 216 | +# Organize in flat structure for processing |
| 217 | +yarn i18n-download --organize-by flat |
| 218 | +``` |
| 219 | + |
| 220 | +### **3. Development & Testing** |
| 221 | + |
| 222 | +```bash |
| 223 | +# Preview what would be downloaded |
| 224 | +yarn i18n-download --dry-run |
| 225 | + |
| 226 | +# Upload with cleanup |
| 227 | +CLEAN_AFTER_UPLOAD=1 yarn i18n-upload |
| 228 | +``` |
| 229 | + |
| 230 | +## 🗂️ Caching Strategy |
| 231 | + |
| 232 | +### **Upload Cache** (`.ui-i18n-cache/`) |
| 233 | +- **Purpose**: Prevent re-uploading unchanged JSON files |
| 234 | +- **Key**: SHA256 hash of file contents |
| 235 | +- **Behavior**: Only cache after successful upload |
| 236 | + |
| 237 | +### **Download Cache** (`.ui-i18n-download-cache/`) |
| 238 | +- **Purpose**: Prevent re-downloading completed jobs |
| 239 | +- **Key**: TMS job ID |
| 240 | +- **Behavior**: Tracks processed job IDs with metadata |
| 241 | + |
| 242 | +Both caches are organized by release version (`1.8/`, `1.9/`, etc.). |
| 243 | + |
| 244 | +## 🚨 Troubleshooting |
| 245 | + |
| 246 | +### **Common Issues** |
| 247 | + |
| 248 | +#### **Upload Fails: "memsource not found"** |
| 249 | +```bash |
| 250 | +# Source TMS CLI configuration |
| 251 | +source ~/.memsourcerc |
| 252 | +``` |
| 253 | + |
| 254 | +#### **Upload Fails: "Project not found"** |
| 255 | +```bash |
| 256 | +# Verify project ID |
| 257 | +memsource project list --name "Red Hat Developer Hub 1.8" |
| 258 | +``` |
| 259 | + |
| 260 | +#### **TypeScript Extraction Fails** |
| 261 | +```bash |
| 262 | +# Ensure TypeScript is installed |
| 263 | +yarn add -D typescript |
| 264 | +``` |
| 265 | + |
| 266 | +#### **Cache Issues** |
| 267 | +```bash |
| 268 | +# Clear upload cache |
| 269 | +rm -rf .ui-i18n-cache/ |
| 270 | + |
| 271 | +# Clear download cache |
| 272 | +rm -rf .ui-i18n-download-cache/ |
| 273 | +``` |
| 274 | + |
| 275 | +### **Debug Mode** |
| 276 | + |
| 277 | +```bash |
| 278 | +# Dry run to see what would happen |
| 279 | +./collect-and-download.sh --dry-run |
| 280 | + |
| 281 | +# Check TMS jobs |
| 282 | +memsource job list --project-id 33299484 |
| 283 | + |
| 284 | +# Validate JSON files |
| 285 | +find ui-i18n/1.8/ -name "*.json" -exec jq . {} \; |
| 286 | +``` |
| 287 | + |
| 288 | +## 🔗 Related |
| 289 | + |
| 290 | +- **TMS Platform**: [Phrase TMS (Memsource)](https://cloud.memsource.com/web) |
| 291 | +- **Backstage i18n Guide**: [Internationalization](https://backstage.io/docs/plugins/internationalization) |
| 292 | + |
| 293 | +--- |
| 294 | + |
| 295 | +📝 **Last Updated**: September 2024 |
| 296 | +🔧 **Maintainer**: RHDH Team |
0 commit comments