|
88 | 88 | - Watch for placeholders and preserve them in translations |
89 | 89 | - Be mindful of text length in UI elements when translating to languages that might require more characters |
90 | 90 | - Use context-aware translations when the same string has different meanings |
91 | | -- Always validate your translation work by running the missing translations script: |
| 91 | +- Always validate your translation work by running the translation tests: |
92 | 92 | ``` |
93 | | - node scripts/find-missing-translations.js |
| 93 | + npx jest --verbose locales/__tests__/lint-translations.test.ts locales/__tests__/find-missing-i18n-keys.test.ts |
94 | 94 | ``` |
95 | | -- Address any missing translations identified by the script to ensure complete coverage across all locales |
| 95 | +- Address any missing translations identified by the tests by using `node scripts/manage-translations.js` to ensure complete coverage across all locales: |
| 96 | +
|
| 97 | +```sh |
| 98 | +./scripts/manage-translations.js |
| 99 | +Usage: |
| 100 | +Command Line Mode: |
| 101 | + Add/update translations: |
| 102 | + node scripts/manage-translations.js [-v] TRANSLATION_FILE KEY_PATH VALUE [KEY_PATH VALUE...] |
| 103 | + Delete translations: |
| 104 | + node scripts/manage-translations.js [-v] -d TRANSLATION_FILE1 [TRANSLATION_FILE2 ...] [ -- KEY1 ...] |
| 105 | +
|
| 106 | +Key Path Format: |
| 107 | + - Use single dot (.) for nested paths: 'command.newTask.title' |
| 108 | + - Use double dots (..) to include a literal dot in key names (like SMTP byte stuffing): |
| 109 | + 'settings..path' -> { 'settings.path': 'value' } |
| 110 | +
|
| 111 | + Examples: |
| 112 | + 'command.newTask.title' -> { command: { newTask: { title: 'value' } } } |
| 113 | + 'settings..path' -> { 'settings.path': 'value' } |
| 114 | + 'nested.key..with..dots' -> { nested: { 'key.with.dots': 'value' } } |
| 115 | +
|
| 116 | +Line-by-Line JSON Mode (--stdin): |
| 117 | + Each line must be a complete, single JSON object/array |
| 118 | + Multi-line or combined JSON is not supported |
| 119 | +
|
| 120 | + Add/update translations: |
| 121 | + node scripts/manage-translations.js [-v] --stdin TRANSLATION_FILE |
| 122 | + Format: One object per line with exactly one key-value pair: |
| 123 | + {"command.newTask.title": "New Task"} |
| 124 | + {"settings..path": "Custom Path"} |
| 125 | + {"nested.key..with..dots": "Value with dots in key"} |
| 126 | +
|
| 127 | + Delete translations: |
| 128 | + node scripts/manage-translations.js [-v] -d --stdin TRANSLATION_FILE |
| 129 | + Format: One array per line with exactly one key: |
| 130 | + ["command.newTask.title"] |
| 131 | + ["settings..path"] |
| 132 | + ["nested.key..with..dots"] |
| 133 | +
|
| 134 | +Options: |
| 135 | + -v Enable verbose output (shows operations) |
| 136 | + -d Delete mode - remove keys instead of setting them |
| 137 | + --stdin Read line-by-line JSON from stdin |
| 138 | +
|
| 139 | +Examples: |
| 140 | + # Add via command line, it is recommended to execute multiple translations simultaneously. |
| 141 | + # The script expects a single file at a time with multiple key-value pairs, not multiple files. |
| 142 | + node scripts/manage-translations.js package.nls.json command.newTask.title "New Task" [ key2 translation2 ... ] && \ |
| 143 | + node scripts/manage-translations.js package.nls.json settings..path "Custom Path" && \ |
| 144 | + node scripts/manage-translations.js package.nls.json nested.key..with..dots "Value with dots" |
| 145 | +
|
| 146 | + # Add multiple translations (one JSON object per line): |
| 147 | + translations.txt: |
| 148 | + {"command.newTask.title": "New Task"} |
| 149 | + {"settings..path": "Custom Path"} |
| 150 | + node scripts/manage-translations.js --stdin package.nls.json < translations.txt |
| 151 | +
|
| 152 | + # Delete multiple keys (one JSON array per line): |
| 153 | + delete_keys.txt: |
| 154 | + ["command.newTask.title"] |
| 155 | + ["settings..path"] |
| 156 | + ["nested.key..with..dots"] |
| 157 | + node scripts/manage-translations.js -d --stdin package.nls.json < delete_keys.txt |
| 158 | +
|
| 159 | + # Using here document for batching: |
| 160 | + node scripts/manage-translations.js --stdin package.nls.json << EOF |
| 161 | + {"command.newTask.title": "New Task"} |
| 162 | + {"settings..path": "Custom Path"} |
| 163 | + EOF |
| 164 | +
|
| 165 | + # Delete using here document: |
| 166 | + node scripts/manage-translations.js -d --stdin package.nls.json << EOF |
| 167 | + ["command.newTask.title"] |
| 168 | + ["settings..path"] |
| 169 | + ["nested.key..with..dots"] |
| 170 | + EOF |
| 171 | +``` |
96 | 172 |
|
97 | 173 | # 9. TRANSLATOR'S CHECKLIST |
98 | 174 |
|
|
0 commit comments