Skip to content

Commit d21e9bc

Browse files
author
Eric Wheeler
committed
feat: migrate translation validation to Jest tests
Replace find-missing-translations.js script with Jest tests for improved: - Test organization and reporting - Error handling and validation - Integration with existing test infrastructure Added detailed documentation for translation management script usage with examples for adding/updating/deleting translations Signed-off-by: Eric Wheeler <[email protected]>
1 parent d80c896 commit d21e9bc

File tree

2 files changed

+80
-4
lines changed

2 files changed

+80
-4
lines changed

.github/workflows/code-qa.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
- name: Install dependencies
4545
run: npm run install:all
4646
- name: Verify all translations are complete
47-
run: node scripts/find-missing-translations.js
47+
run: npx jest --verbose locales/__tests__/lint-translations.test.ts locales/__tests__/find-missing-i18n-keys.test.ts
4848

4949
knip:
5050
runs-on: ubuntu-latest

.roo/rules-translate/001-general-rules.md

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,87 @@
8888
- Watch for placeholders and preserve them in translations
8989
- Be mindful of text length in UI elements when translating to languages that might require more characters
9090
- 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:
9292
```
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
9494
```
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+
```
96172

97173
# 9. TRANSLATOR'S CHECKLIST
98174

0 commit comments

Comments
 (0)