Skip to content

Commit ee0317d

Browse files
Merge main f015dae (fix(commands): prevent code execution in command frontmatter Zoo-Code-Org#2420) into the u6 branch for the 1932 refresh: the tip is carried in by merge rather than by replaying history, and the two paths this pull touches are byte-for-byte unchanged by the trunk since the merge base (source blob 3c1d33a identical at merge base and at tip), so no hunk here is repaired by hand
2 parents fbd87ac + f015dae commit ee0317d

144 files changed

Lines changed: 3296 additions & 463 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/code-qa.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,12 @@ jobs:
7474
uses: ./.github/actions/setup-node-pnpm
7575
with:
7676
install-args: "--frozen-lockfile"
77+
- name: Test translation check scripts
78+
run: pnpm test:translations-check
7779
- name: Verify all translations are complete
7880
run: node scripts/find-missing-translations.js
81+
- name: Verify plural forms follow CLDR
82+
run: node scripts/validate-plural-forms.js
7983
- name: Verify t() calls pass every interpolation variable
8084
run: node scripts/check-i18n-interpolation.js
8185

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

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,65 @@
5454
# 5. TECHNICAL IMPLEMENTATION
5555

5656
- Use namespaces to organize translations logically
57-
- Handle pluralization using i18next's built-in capabilities
57+
- Handle pluralization with i18next plural keys that follow CLDR rules (see section 6)
5858
- Implement proper interpolation for variables using {{variable}} syntax
5959
- Don't include defaultValue. The `en` translations are the fallback
6060
- Always use apply_diff instead of write_to_file when editing existing translation files (much faster and more reliable)
6161
- When using apply_diff, carefully identify the exact JSON structure to edit to avoid syntax errors
6262
- Placeholders (like {{variable}}) must remain exactly identical to the English source to maintain code integration and prevent syntax errors
6363

64-
# 6. WORKFLOW AND APPROACH
64+
# 6. PLURALIZATION (CLDR)
65+
66+
i18next v25 picks a plural form with `Intl.PluralRules`, which implements the [CLDR plural rules](https://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html). Any string that counts something must use plural keys.
67+
68+
- Never fake plurals with "(s)", "файл(ов)", "richiesta/e" or similar. Split the string into plural forms instead.
69+
- Pass the number as `count`: `t("ns:key", { count: n })`. With `<Trans>`, pass `count={n}` or `values={{ count: n }}`.
70+
- Name the keys `key_one`, `key_few`, `key_many`, `key_other` (plus an optional `key_zero`). Do not keep a bare `key` next to them: i18next uses it in place of any missing form, which hides the gap.
71+
- Each locale must have exactly its CLDR forms. When a form is missing, i18next falls back to the bare key and then to English. Extra forms are never shown:
72+
73+
| Locales | Forms | What the forms cover |
74+
| ---------------------------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------- |
75+
| en, de, nl, tr | `one`, `other` | `one` = 1 |
76+
| hi | `one`, `other` | `one` = 0, 1 |
77+
| fr, pt-BR | `one`, `many`, `other` | `one` = 0, 1; `many` = exact millions (1000000) |
78+
| ca, es, it | `one`, `many`, `other` | `one` = 1; `many` = exact millions (1000000) |
79+
| ru | `one`, `few`, `many`, `other` | `one` = 1, 21, 31, 101 (not 11); `few` = 2–4, 22–24 (not 12–14); `many` = 0, 5–20, 25–30; `other` = fractions |
80+
| pl | `one`, `few`, `many`, `other` | `one` = 1 only; `few` = 2–4, 22–24 (not 12–14); `many` = 0, 5–21, 25–31; `other` = fractions |
81+
| id, ja, ko, vi, zh-CN, zh-TW | `other` | No `_one`: these languages do not inflect for number |
82+
83+
- Every form, including `_one`, must contain `{{count}}`. Do not hardcode "1": `_one` also covers 21 in ru and 0 in fr, pt-BR and hi.
84+
- `_many` in ca, es, fr, it and pt-BR only applies to exact millions printed as digits. Copy the `_other` text.
85+
- `_other` in ru and pl only applies to fractions (1.5). Use the genitive singular: ru "1,5 минуты" (same as `_few`), pl "1,5 minuty", "1,5 wyniku".
86+
- The form depends on the whole phrase, not just the noun. Check the case the preposition or verb requires:
87+
- ru "удалить {{count}} задачу / задачи / задач"
88+
- ru "до {{count}} запроса / запросов / запросов"
89+
- pl negation "nie udało się odłączyć {{count}} serwera / serwerów / serwerów"
90+
- If another number governs the noun (e.g. "{{count}} of {{total}}"), rephrase so the noun no longer depends on a number: "Импортировано историй задач: {{count}} из {{total}}".
91+
- `_zero` is an i18next override for count 0 in every language. Add it in every locale when the English key has it. In ru and pl, 0 otherwise uses `_many`.
92+
- Do not pluralize money amounts, unit abbreviations ("{{count}}s"), numbers that JavaScript updates live in the DOM, or phrases with no counted noun ("and {{count}} more").
93+
94+
Example:
95+
96+
```jsonc
97+
// en
98+
"subtasks_one": "{{count}} subtask",
99+
"subtasks_other": "{{count}} subtasks",
100+
101+
// ru
102+
"subtasks_one": "{{count}} подзадача",
103+
"subtasks_few": "{{count}} подзадачи",
104+
"subtasks_many": "{{count}} подзадач",
105+
"subtasks_other": "{{count}} подзадачи",
106+
107+
// ja
108+
"subtasks_other": "{{count}} サブタスク",
109+
```
110+
111+
To list the plural forms of any locale, run: `node -p 'new Intl.PluralRules("<locale>").resolvedOptions().pluralCategories'`
112+
113+
`node scripts/find-missing-translations.js` reports a plural key only when a locale has no key with its base name (`key` or `key_*`). `node scripts/validate-plural-forms.js` reports missing forms, forms without `{{count}}`, extra forms, bare keys next to plural forms and plural mistakes in English.
114+
115+
# 7. WORKFLOW AND APPROACH
65116

66117
- First add or modify English strings, then ask for confirmation before translating to all other languages
67118
- Use this process for each localization task:
@@ -78,16 +129,17 @@
78129
- Tooltip text: Can be slightly more descriptive
79130
- Preserve the original perspective: If text is a user command directed at the software, ensure the translation maintains this direction, avoiding language that makes it sound like an instruction from the system to the user
80131

81-
# 7. COMMON PITFALLS TO AVOID
132+
# 8. COMMON PITFALLS TO AVOID
82133

83134
- Switching between formal and informal addressing styles - always stay informal ("du" not "Sie")
84135
- Translating or altering technical terms and brand names that should remain in English
85136
- Modifying or removing placeholders like {{variable}} - these must remain identical
86137
- Translating domain-specific terms that are commonly used in English in the target language
87138
- Changing the meaning or nuance of instructions or error messages
88139
- Forgetting to maintain consistent terminology throughout the translation
140+
- Copying the English `_one`/`_other` pair into a locale with different plural forms, or writing "(s)"-style plurals
89141

90-
# 8. QUALITY ASSURANCE
142+
# 9. QUALITY ASSURANCE
91143

92144
- Maintain consistent terminology across all translations
93145
- Respect the JSON structure of translation files
@@ -99,11 +151,16 @@
99151
node scripts/find-missing-translations.js
100152
```
101153
- Address any missing translations identified by the script to ensure complete coverage across all locales
154+
- When you add or change plural keys, also run the plural forms script and fix every problem it reports:
155+
```
156+
node scripts/validate-plural-forms.js
157+
```
102158
103-
# 9. TRANSLATOR'S CHECKLIST
159+
# 10. TRANSLATOR'S CHECKLIST
104160
105161
- ✓ Used informal tone consistently ("du" not "Sie")
106162
- ✓ Preserved all placeholders exactly as in the English source
163+
- ✓ Gave each plural key exactly the locale's CLDR forms, each containing `{{count}}`
107164
- ✓ Maintained consistent terminology with existing translations
108165
- ✓ Kept technical terms and brand names unchanged where appropriate
109166
- ✓ Preserved the original perspective (user→system vs system→user)

‎.roo/skills/roo-translation/SKILL.md‎

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,64 @@ React component usage:
100100
## Technical Implementation
101101

102102
- Use namespaces to organize translations logically
103-
- Handle pluralization using i18next's built-in capabilities
103+
- Handle pluralization with i18next plural keys that follow CLDR rules (see [Pluralization (CLDR)](#pluralization-cldr))
104104
- Implement proper interpolation for variables using `{{variable}}` syntax
105105
- Don't include `defaultValue`. The `en` translations are the fallback
106106
- Always use `apply_diff` instead of `write_to_file` when editing existing translation files (much faster and more reliable)
107107
- When using `apply_diff`, carefully identify the exact JSON structure to edit to avoid syntax errors
108108
- Placeholders (like `{{variable}}`) must remain exactly identical to the English source to maintain code integration and prevent syntax errors
109109

110+
## Pluralization (CLDR)
111+
112+
i18next v25 picks a plural form with `Intl.PluralRules`, which implements the [CLDR plural rules](https://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html). Any string that counts something must use plural keys.
113+
114+
- Never fake plurals with "(s)", "файл(ов)", "richiesta/e" or similar. Split the string into plural forms instead.
115+
- Pass the number as `count`: `t("ns:key", { count: n })`. With `<Trans>`, pass `count={n}` or `values={{ count: n }}`.
116+
- Name the keys `key_one`, `key_few`, `key_many`, `key_other` (plus an optional `key_zero`). Do not keep a bare `key` next to them: i18next uses it in place of any missing form, which hides the gap.
117+
- Each locale must have exactly its CLDR forms. When a form is missing, i18next falls back to the bare key and then to English. Extra forms are never shown:
118+
119+
| Locales | Forms | What the forms cover |
120+
| ---------------------------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------- |
121+
| en, de, nl, tr | `one`, `other` | `one` = 1 |
122+
| hi | `one`, `other` | `one` = 0, 1 |
123+
| fr, pt-BR | `one`, `many`, `other` | `one` = 0, 1; `many` = exact millions (1000000) |
124+
| ca, es, it | `one`, `many`, `other` | `one` = 1; `many` = exact millions (1000000) |
125+
| ru | `one`, `few`, `many`, `other` | `one` = 1, 21, 31, 101 (not 11); `few` = 2–4, 22–24 (not 12–14); `many` = 0, 5–20, 25–30; `other` = fractions |
126+
| pl | `one`, `few`, `many`, `other` | `one` = 1 only; `few` = 2–4, 22–24 (not 12–14); `many` = 0, 5–21, 25–31; `other` = fractions |
127+
| id, ja, ko, vi, zh-CN, zh-TW | `other` | No `_one`: these languages do not inflect for number |
128+
129+
- Every form, including `_one`, must contain `{{count}}`. Do not hardcode "1": `_one` also covers 21 in ru and 0 in fr, pt-BR and hi.
130+
- `_many` in ca, es, fr, it and pt-BR only applies to exact millions printed as digits. Copy the `_other` text.
131+
- `_other` in ru and pl only applies to fractions (1.5). Use the genitive singular: ru "1,5 минуты" (same as `_few`), pl "1,5 minuty", "1,5 wyniku".
132+
- The form depends on the whole phrase, not just the noun. Check the case the preposition or verb requires:
133+
- ru "удалить {{count}} задачу / задачи / задач"
134+
- ru "до {{count}} запроса / запросов / запросов"
135+
- pl negation "nie udało się odłączyć {{count}} serwera / serwerów / serwerów"
136+
- If another number governs the noun (e.g. "{{count}} of {{total}}"), rephrase so the noun no longer depends on a number: "Импортировано историй задач: {{count}} из {{total}}".
137+
- `_zero` is an i18next override for count 0 in every language. Add it in every locale when the English key has it. In ru and pl, 0 otherwise uses `_many`.
138+
- Do not pluralize money amounts, unit abbreviations ("{{count}}s"), numbers that JavaScript updates live in the DOM, or phrases with no counted noun ("and {{count}} more").
139+
140+
Example:
141+
142+
```jsonc
143+
// en
144+
"subtasks_one": "{{count}} subtask",
145+
"subtasks_other": "{{count}} subtasks",
146+
147+
// ru
148+
"subtasks_one": "{{count}} подзадача",
149+
"subtasks_few": "{{count}} подзадачи",
150+
"subtasks_many": "{{count}} подзадач",
151+
"subtasks_other": "{{count}} подзадачи",
152+
153+
// ja
154+
"subtasks_other": "{{count}} サブタスク",
155+
```
156+
157+
To list the plural forms of any locale, run: `node -p 'new Intl.PluralRules("<locale>").resolvedOptions().pluralCategories'`.
158+
159+
`node scripts/find-missing-translations.js` reports a plural key only when a locale has no key with its base name (`key` or `key_*`). `node scripts/validate-plural-forms.js` reports missing forms, forms without `{{count}}`, extra forms, bare keys next to plural forms and plural mistakes in English.
160+
110161
## Translation Workflow
111162

112163
1. First add or modify English strings, then ask for confirmation before translating to all other languages
@@ -137,6 +188,12 @@ node scripts/find-missing-translations.js
137188

138189
Address any missing translations identified by the script to ensure complete coverage across all locales.
139190

191+
When you add or change plural keys, also run the plural forms script and fix every problem it reports:
192+
193+
```bash
194+
node scripts/validate-plural-forms.js
195+
```
196+
140197
## Common Pitfalls to Avoid
141198

142199
- Switching between formal and informal addressing styles - always stay informal ("du" not "Sie")
@@ -145,11 +202,13 @@ Address any missing translations identified by the script to ensure complete cov
145202
- Translating domain-specific terms that are commonly used in English in the target language
146203
- Changing the meaning or nuance of instructions or error messages
147204
- Forgetting to maintain consistent terminology throughout the translation
205+
- Copying the English `_one`/`_other` pair into a locale with different plural forms, or writing "(s)"-style plurals
148206

149207
## Translator's Checklist
150208

151209
- ✓ Used informal tone consistently ("du" not "Sie")
152210
- ✓ Preserved all placeholders exactly as in the English source
211+
- ✓ Gave each plural key exactly the locale's CLDR forms, each containing `{{count}}`
153212
- ✓ Maintained consistent terminology with existing translations
154213
- ✓ Kept technical terms and brand names unchanged where appropriate
155214
- ✓ Preserved the original perspective (user→system vs system→user)

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
"knip": "knip --treat-config-hints-as-errors",
4242
"npm:publish:types": "pnpm --filter @roo-code/types npm:publish",
4343
"knip:production": "knip --production --treat-config-hints-as-errors",
44-
"test:knip-policy": "node --test scripts/knip-policy.test.mjs"
44+
"test:knip-policy": "node --test scripts/knip-policy.test.mjs",
45+
"test:translations-check": "node --test scripts/find-missing-translations.test.mjs scripts/validate-plural-forms.test.mjs"
4546
},
4647
"devDependencies": {
4748
"@changesets/cli": "2.31.1",

‎scripts/find-missing-translations.js‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
const path = require("path")
1515
const { promises: fs } = require("fs")
16+
const { PLURAL_FORMS, PLURAL_KEY, findPluralBases } = require("./lib/plural-forms")
1617

1718
const readFile = fs.readFile
1819
const readdir = fs.readdir
@@ -47,6 +48,8 @@ Find Missing Translations
4748
4849
A utility script to identify missing translations across locale files.
4950
Compares non-English locale files to the English ones to find any missing keys.
51+
A plural key is reported only when a locale has no key with its base name (e.g. no "files_*").
52+
Run validate-plural-forms.js to check that each locale has exactly its CLDR plural forms.
5053
5154
Usage:
5255
node scripts/find-missing-translations.js [options]
@@ -95,6 +98,22 @@ function findKeys(obj, parentKey = "") {
9598
return keys
9699
}
97100

101+
// A plural key is translated when the locale has any key with its base name ("files" or "files_<form>").
102+
// Locales use different plural suffixes (ru: _few, _many; ja: only _other), so the suffixes are not
103+
// compared here. validate-plural-forms.js checks that each locale has exactly its CLDR forms.
104+
function findMissingPluralKeys(localeContent, pluralBases) {
105+
const missing = []
106+
107+
for (const [base, { englishValue }] of pluralBases) {
108+
const related = [base, ...PLURAL_FORMS.map((form) => `${base}_${form}`)]
109+
if (related.every((key) => getValueAtPath(localeContent, key) === undefined)) {
110+
missing.push({ key: `${base}_*`, englishValue })
111+
}
112+
}
113+
114+
return missing
115+
}
116+
98117
// Get value at a dotted path in an object
99118
function getValueAtPath(obj, path) {
100119
const parts = path.split(".")
@@ -190,8 +209,14 @@ async function checkAreaTranslations(area) {
190209
`Checking ${englishFileContents.length} translation file(s): ${englishFileContents.map((f) => f.name).join(", ")}`,
191210
)
192211

193-
// Precompute English keys per file
212+
// Precompute English keys and plural keys per file
194213
const englishFileKeys = new Map(englishFileContents.map((f) => [f.name, findKeys(f.content)]))
214+
const englishPluralBases = new Map(
215+
englishFileContents.map((f) => [
216+
f.name,
217+
findPluralBases(englishFileKeys.get(f.name).map((key) => [key, getValueAtPath(f.content, key)])),
218+
]),
219+
)
195220

196221
// Results object to store missing translations
197222
const missingTranslations = {}
@@ -220,6 +245,9 @@ async function checkAreaTranslations(area) {
220245
const missingKeys = []
221246

222247
for (const key of englishKeys) {
248+
// Plural forms differ between locales, so plural keys are matched by base name below
249+
if (PLURAL_KEY.test(key)) continue
250+
223251
const englishValue = getValueAtPath(englishContent, key)
224252
const localeValue = getValueAtPath(localeContent, key)
225253

@@ -231,6 +259,8 @@ async function checkAreaTranslations(area) {
231259
}
232260
}
233261

262+
missingKeys.push(...findMissingPluralKeys(localeContent, englishPluralBases.get(name)))
263+
234264
if (missingKeys.length > 0) {
235265
missingTranslations[locale][name] = missingKeys
236266
}

0 commit comments

Comments
 (0)