|
| 1 | +# Dates-LE Internationalization (I18N) Guide |
| 2 | + |
| 3 | +## Goals and philosophy |
| 4 | + |
| 5 | +- Inclusive by default: all user‑facing text is localizable. |
| 6 | +- Privacy‑first and offline: no network calls; translations ship with the extension. |
| 7 | +- Predictable keys: two namespaces — `manifest.*` for `package.json` UI and `runtime.*` for in‑code strings. |
| 8 | +- Safe fallbacks: English is bundled and used when a key or locale is missing. |
| 9 | +- Translator‑friendly: consistent placeholders, small focused sentences, and a source `language.json` catalogue. |
| 10 | + |
| 11 | +Non‑goals: |
| 12 | +- Remote translation fetching or telemetry. |
| 13 | +- Complex runtime pluralization logic. We use positional `{0}` placeholders with `vscode-nls`. |
| 14 | + |
| 15 | +--- |
| 16 | + |
| 17 | +## File layout |
| 18 | + |
| 19 | +``` |
| 20 | +src/i18n/ |
| 21 | + package.nls.json # Base English strings for package.json |
| 22 | + runtime.json # Runtime strings for in-code messages |
| 23 | + package.nls.de.json # German translations |
| 24 | + package.nls.es.json # Spanish translations |
| 25 | + package.nls.fr.json # French translations |
| 26 | + package.nls.id.json # Indonesian translations |
| 27 | + package.nls.it.json # Italian translations |
| 28 | + package.nls.ja.json # Japanese translations |
| 29 | + package.nls.ko.json # Korean translations |
| 30 | + package.nls.ru.json # Russian translations |
| 31 | + package.nls.uk.json # Ukrainian translations |
| 32 | + package.nls.vi.json # Vietnamese translations |
| 33 | + package.nls.zh-cn.json # Chinese (Simplified) translations |
| 34 | +``` |
| 35 | + |
| 36 | +--- |
| 37 | + |
| 38 | +## Key namespaces |
| 39 | + |
| 40 | +### `manifest.*` keys (package.json UI) |
| 41 | + |
| 42 | +Used for VS Code extension manifest strings: |
| 43 | + |
| 44 | +```json |
| 45 | +{ |
| 46 | + "manifest.ext.name": "Dates-LE", |
| 47 | + "manifest.ext.description": "Extract and analyze dates from various file formats including logs, configuration files, and code", |
| 48 | + "manifest.command.category": "Dates-LE", |
| 49 | + "manifest.command.extract.title": "Extract Dates", |
| 50 | + "manifest.command.convert.title": "Convert Date Formats", |
| 51 | + "manifest.command.analyze.title": "Analyze Dates", |
| 52 | + "manifest.settings.title": "Dates-LE Settings" |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +### `runtime.*` keys (in-code messages) |
| 57 | + |
| 58 | +Used for dynamic messages, errors, and user feedback: |
| 59 | + |
| 60 | +```json |
| 61 | +{ |
| 62 | + "runtime.extract.no-editor": "No active editor found", |
| 63 | + "runtime.extract.progress": "Extracting dates...", |
| 64 | + "runtime.extract.success": "Extracted {0} dates", |
| 65 | + "runtime.error.parsing": "Parsing error", |
| 66 | + "runtime.error.validation": "Validation error" |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +--- |
| 71 | + |
| 72 | +## Usage in code |
| 73 | + |
| 74 | +### Package.json localization |
| 75 | + |
| 76 | +Reference keys in `package.json` using `%key%` syntax: |
| 77 | + |
| 78 | +```json |
| 79 | +{ |
| 80 | + "commands": [ |
| 81 | + { |
| 82 | + "command": "dates-le.extractDates", |
| 83 | + "title": "%manifest.command.extract.title%", |
| 84 | + "category": "%manifest.command.category%" |
| 85 | + } |
| 86 | + ], |
| 87 | + "configuration": { |
| 88 | + "title": "%manifest.settings.title%", |
| 89 | + "properties": { |
| 90 | + "dates-le.enabled": { |
| 91 | + "description": "%manifest.settings.enabled.desc%" |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | +} |
| 96 | +``` |
| 97 | + |
| 98 | +### Runtime localization |
| 99 | + |
| 100 | +Use `vscode-nls` for runtime messages: |
| 101 | + |
| 102 | +```typescript |
| 103 | +import * as nls from 'vscode-nls' |
| 104 | + |
| 105 | +const localize = nls.config({ messageFormat: nls.MessageFormat.file })() |
| 106 | + |
| 107 | +// Simple message |
| 108 | +const message = localize('runtime.extract.no-editor', 'No active editor found') |
| 109 | + |
| 110 | +// Message with parameters |
| 111 | +const successMessage = localize('runtime.extract.success', 'Extracted {0} dates', count) |
| 112 | + |
| 113 | +// Error message |
| 114 | +const errorMessage = localize('runtime.error.parsing', 'Parsing error: {0}', errorDetails) |
| 115 | +``` |
| 116 | + |
| 117 | +--- |
| 118 | + |
| 119 | +## Translation guidelines |
| 120 | + |
| 121 | +### Key naming conventions |
| 122 | + |
| 123 | +- Use descriptive, hierarchical names: `manifest.settings.extraction.includeComments.desc` |
| 124 | +- Keep keys under 50 characters when possible |
| 125 | +- Use consistent terminology across all translations |
| 126 | +- Group related keys together |
| 127 | + |
| 128 | +### Message formatting |
| 129 | + |
| 130 | +- Use `{0}`, `{1}`, `{2}` for positional parameters |
| 131 | +- Keep messages concise and clear |
| 132 | +- Avoid technical jargon when possible |
| 133 | +- Use consistent punctuation and capitalization |
| 134 | + |
| 135 | +### Example translation |
| 136 | + |
| 137 | +**English (base)**: |
| 138 | +```json |
| 139 | +{ |
| 140 | + "manifest.settings.extraction.includeComments.desc": "Include dates found in comments and documentation", |
| 141 | + "runtime.extract.success": "Extracted {0} dates from {1} file" |
| 142 | +} |
| 143 | +``` |
| 144 | + |
| 145 | +**German translation**: |
| 146 | +```json |
| 147 | +{ |
| 148 | + "manifest.settings.extraction.includeComments.desc": "Daten in Kommentaren und Dokumentation einbeziehen", |
| 149 | + "runtime.extract.success": "{0} Daten aus {1} Datei extrahiert" |
| 150 | +} |
| 151 | +``` |
| 152 | + |
| 153 | +--- |
| 154 | + |
| 155 | +## Adding new translations |
| 156 | + |
| 157 | +### 1. Add keys to base files |
| 158 | + |
| 159 | +Add new keys to `src/i18n/package.nls.json` and `src/i18n/runtime.json`: |
| 160 | + |
| 161 | +```json |
| 162 | +{ |
| 163 | + "manifest.settings.newFeature.desc": "Description of new feature", |
| 164 | + "runtime.newFeature.success": "New feature completed successfully" |
| 165 | +} |
| 166 | +``` |
| 167 | + |
| 168 | +### 2. Update package.json |
| 169 | + |
| 170 | +Reference the new keys in `package.json`: |
| 171 | + |
| 172 | +```json |
| 173 | +{ |
| 174 | + "configuration": { |
| 175 | + "properties": { |
| 176 | + "dates-le.newFeature": { |
| 177 | + "description": "%manifest.settings.newFeature.desc%" |
| 178 | + } |
| 179 | + } |
| 180 | + } |
| 181 | +} |
| 182 | +``` |
| 183 | + |
| 184 | +### 3. Use in code |
| 185 | + |
| 186 | +Add runtime usage: |
| 187 | + |
| 188 | +```typescript |
| 189 | +const message = localize('runtime.newFeature.success', 'New feature completed successfully') |
| 190 | +``` |
| 191 | + |
| 192 | +### 4. Add translations |
| 193 | + |
| 194 | +Create or update translation files for each supported language: |
| 195 | + |
| 196 | +```json |
| 197 | +{ |
| 198 | + "manifest.settings.newFeature.desc": "Beschreibung der neuen Funktion", |
| 199 | + "runtime.newFeature.success": "Neue Funktion erfolgreich abgeschlossen" |
| 200 | +} |
| 201 | +``` |
| 202 | + |
| 203 | +--- |
| 204 | + |
| 205 | +## Testing translations |
| 206 | + |
| 207 | +### Local testing |
| 208 | + |
| 209 | +1. Set VS Code locale: `Ctrl+Shift+P` → "Configure Display Language" |
| 210 | +2. Restart VS Code |
| 211 | +3. Test extension functionality |
| 212 | +4. Verify all strings are translated |
| 213 | + |
| 214 | +### Translation validation |
| 215 | + |
| 216 | +- Check for missing keys in translation files |
| 217 | +- Verify parameter placeholders match between languages |
| 218 | +- Test with different locales and fallback scenarios |
| 219 | +- Ensure consistent terminology across all languages |
| 220 | + |
| 221 | +--- |
| 222 | + |
| 223 | +## Future enhancements |
| 224 | + |
| 225 | +### Planned features |
| 226 | + |
| 227 | +- **Portuguese (Brazil) support**: `package.nls.pt-br.json` |
| 228 | +- **Additional languages**: Based on user demand and community contributions |
| 229 | +- **Translation validation**: Automated checks for missing keys and parameter mismatches |
| 230 | +- **Community contributions**: Guidelines for external translation contributions |
| 231 | + |
| 232 | +### Contributing translations |
| 233 | + |
| 234 | +1. Fork the repository |
| 235 | +2. Add translation files for your language |
| 236 | +3. Test thoroughly with the target locale |
| 237 | +4. Submit a pull request with translation files and test results |
| 238 | + |
| 239 | +--- |
| 240 | + |
| 241 | +## Troubleshooting |
| 242 | + |
| 243 | +### Common issues |
| 244 | + |
| 245 | +**Missing translations** |
| 246 | +- Check that translation files are in the correct location |
| 247 | +- Verify key names match exactly between base and translation files |
| 248 | +- Ensure VS Code is restarted after adding new translations |
| 249 | + |
| 250 | +**Parameter mismatches** |
| 251 | +- Verify `{0}`, `{1}`, etc. placeholders are consistent |
| 252 | +- Test with different parameter values |
| 253 | +- Check for proper escaping of special characters |
| 254 | + |
| 255 | +**Fallback behavior** |
| 256 | +- English strings are used when translations are missing |
| 257 | +- Check VS Code locale settings |
| 258 | +- Verify translation files are properly formatted JSON |
| 259 | + |
| 260 | +### Debug tips |
| 261 | + |
| 262 | +- Use VS Code Developer Tools to inspect localized strings |
| 263 | +- Check the Output panel for i18n-related errors |
| 264 | +- Test with different VS Code locales to verify fallback behavior |
| 265 | +- Use browser dev tools to inspect DOM for localized content |
0 commit comments