Skip to content

Commit 8c00ff5

Browse files
ericyangpanclaude
andcommitted
feat(skills): add i18n-dedup-optimizer skill
Add a new Claude Code skill for analyzing and optimizing duplicate translation keys in internationalization files. Features: - Scan all locale JSON files for duplicate translation values - Identify exact duplicates and semantic patterns - Generate detailed analysis reports with statistics - Suggest consolidation strategies following DRY principles - Support for namespace-based i18n structure with @ references - 5-step workflow: analyze → review → propose → consolidate → verify Components: - scripts/analyze-duplicates.mjs: Node.js script to scan and analyze duplicates - references/i18n-structure.md: Comprehensive i18n structure documentation - SKILL.md: Complete workflow and best practices guide This skill helps maintain clean, DRY translation files by consolidating duplicate values into shared namespaces while preserving semantic meaning across all supported languages. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 859d381 commit 8c00ff5

File tree

4 files changed

+751
-1
lines changed

4 files changed

+751
-1
lines changed
Lines changed: 294 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,294 @@
1+
---
2+
name: i18n-dedup-optimizer
3+
description: Analyze and optimize duplicate translation keys in English locale files. Use this skill when working on internationalization (i18n) improvements, reducing translation duplication, or consolidating repeated translation values across locale JSON files. The skill identifies duplicate values, suggests consolidation strategies, and helps refactor translation references to follow DRY principles.
4+
---
5+
6+
# I18n Dedup Optimizer
7+
8+
## Overview
9+
10+
Analyze and optimize duplicate translation keys in the English locale files to follow DRY (Don't Repeat Yourself) principles. This skill identifies duplicate translation values, suggests consolidation opportunities, and guides the refactoring process to reduce redundancy while maintaining proper i18n structure.
11+
12+
## Workflow
13+
14+
The optimization process follows a systematic workflow to ensure safe and effective consolidation of duplicate translations.
15+
16+
### Step 1: Run Duplicate Analysis
17+
18+
Execute the analysis script to identify all duplicate translation values in the English locale files:
19+
20+
```bash
21+
node .claude/skills/i18n-dedup-optimizer/scripts/analyze-duplicates.mjs
22+
```
23+
24+
The script will:
25+
- Scan all JSON files in `locales/en/`
26+
- Identify exact duplicate values (same text appearing multiple times)
27+
- Detect semantic patterns (e.g., "Back to X", "View X")
28+
- Generate a detailed report with statistics and suggestions
29+
30+
**Output includes:**
31+
- Total files and translation keys analyzed
32+
- Number of existing references (already optimized)
33+
- List of duplicate values with their locations
34+
- Pattern analysis for common duplications
35+
- Consolidation suggestions with recommended target keys
36+
37+
### Step 2: Review Analysis Report
38+
39+
Carefully review the analysis output to understand the duplication landscape:
40+
41+
1. **Check statistics**: Understand the scope of duplication
42+
2. **Review exact duplicates**: Identify high-priority consolidation targets
43+
3. **Examine patterns**: Look for systematic duplication patterns
44+
4. **Evaluate suggestions**: Assess the proposed consolidation targets
45+
46+
**Key considerations:**
47+
- Not all duplicates should be consolidated (some may be coincidentally identical)
48+
- Context matters - ensure consolidated keys make semantic sense
49+
- Prefer moving values to appropriate namespaces (`shared`, `components`, or `pages`)
50+
51+
Refer to `references/i18n-structure.md` for detailed information about:
52+
- Namespace organization and hierarchy
53+
- Reference syntax (`@:namespace.key.path`)
54+
- Best practices for consolidation
55+
- Common duplication patterns
56+
57+
### Step 3: Propose Consolidation Strategy
58+
59+
Based on the analysis, create a consolidation plan for user approval:
60+
61+
1. **Categorize duplicates** by priority:
62+
- High priority: Exact duplicates used 3+ times
63+
- Medium priority: Exact duplicates used 2 times
64+
- Low priority: Parameterized duplicates or edge cases
65+
66+
2. **Group by consolidation target**:
67+
- `shared` namespace for cross-cutting terms
68+
- `components` namespace for UI-related terms
69+
- Keep page-specific terms in page namespaces
70+
71+
3. **Prepare detailed proposal** including:
72+
- List of values to consolidate
73+
- Target location for each value
74+
- Keys that will be updated to use references
75+
- Estimated impact (number of keys reduced)
76+
77+
**Present the proposal to the user in a clear, structured format:**
78+
79+
```
80+
Consolidation Proposal
81+
═══════════════════════
82+
83+
Priority 1: High-Impact Duplicates
84+
───────────────────────────────────
85+
1. "Compare All" (3 occurrences)
86+
Target: shared.actions.compareAll
87+
Will update:
88+
- pages.clis.compareAll → @:shared.actions.compareAll
89+
- pages.extensions.compareAll → @:shared.actions.compareAll
90+
- pages.ides.compareAll → @:shared.actions.compareAll
91+
92+
2. "Back to" (5 occurrences)
93+
Target: shared.actions.backTo
94+
Will update: [list specific keys]
95+
...
96+
97+
Estimated reduction: 15 translation keys
98+
```
99+
100+
**Wait for user approval before proceeding.**
101+
102+
### Step 4: Perform Consolidation
103+
104+
Once approved, systematically refactor the translation files:
105+
106+
#### 4.1 Update JSON Files
107+
108+
For each approved consolidation:
109+
110+
1. **Ensure target key exists** in the appropriate namespace file
111+
2. **Update referencing keys** to use `@:` syntax
112+
3. **Remove duplicate values** from their original locations
113+
114+
**Example transformation:**
115+
116+
Before:
117+
```json
118+
// pages/clis.json
119+
{
120+
"clis": {
121+
"compareAll": "Compare All"
122+
}
123+
}
124+
125+
// pages/extensions.json
126+
{
127+
"extensions": {
128+
"compareAll": "Compare All"
129+
}
130+
}
131+
```
132+
133+
After:
134+
```json
135+
// shared.json
136+
{
137+
"actions": {
138+
"compareAll": "Compare All"
139+
}
140+
}
141+
142+
// pages/clis.json
143+
{
144+
"clis": {
145+
"compareAll": "@:shared.actions.compareAll"
146+
}
147+
}
148+
149+
// pages/extensions.json
150+
{
151+
"extensions": {
152+
"compareAll": "@:shared.actions.compareAll"
153+
}
154+
}
155+
```
156+
157+
#### 4.2 Update Component/Page Code (if needed)
158+
159+
If translation key paths change, update the corresponding component or page code:
160+
161+
**Before:**
162+
```tsx
163+
t('pages.clis.compareAll')
164+
```
165+
166+
**After:**
167+
```tsx
168+
// If the key path is preserved, no code change needed
169+
t('pages.clis.compareAll') // Still works via reference
170+
171+
// If the key path changed directly
172+
t('shared.actions.compareAll')
173+
```
174+
175+
**Note:** When using references (`@:`), the original key path still works, so code updates are often unnecessary. Only update code if keys are completely removed or restructured.
176+
177+
#### 4.3 Apply to All Languages
178+
179+
After updating English locale files:
180+
181+
1. **Copy the structure** to other language directories (`zh-Hans`, `de`, `ko`)
182+
2. **Keep translated values** but use same `@:` references
183+
3. **Maintain consistency** across all language files
184+
185+
**Example for German:**
186+
```json
187+
// locales/de/shared.json
188+
{
189+
"actions": {
190+
"compareAll": "Alle vergleichen" // Translated value
191+
}
192+
}
193+
194+
// locales/de/pages/clis.json
195+
{
196+
"clis": {
197+
"compareAll": "@:shared.actions.compareAll" // Same reference
198+
}
199+
}
200+
```
201+
202+
### Step 5: Verification
203+
204+
After completing consolidation, verify the changes:
205+
206+
1. **Run the analysis script again** to confirm reduction in duplicates
207+
2. **Build the project** to catch any reference errors:
208+
```bash
209+
npm run build
210+
```
211+
3. **Test key pages** in all supported languages
212+
4. **Check for console warnings** about missing translation keys
213+
214+
**Verification checklist:**
215+
- [ ] Analysis shows reduced duplicate count
216+
- [ ] Build completes without errors
217+
- [ ] All pages render correctly in English
218+
- [ ] All pages render correctly in other languages
219+
- [ ] No console warnings about missing keys
220+
- [ ] Translations display correctly at runtime
221+
222+
## Common Consolidation Patterns
223+
224+
### Action Verbs
225+
Consolidate into `shared.actions`:
226+
- "Compare", "Compare All", "Download", "Explore", "View", "Visit"
227+
- "Follow on {platform}", "Join {platform}", "Watch on {platform}"
228+
- "Back to", "Back to top"
229+
230+
### Platform Names
231+
Use `shared.platforms`:
232+
- "GitHub", "Discord", "LinkedIn", "X (Twitter)", "YouTube", "Reddit"
233+
- "Artificial Analysis", "HuggingFace", "OpenRouter"
234+
235+
### Stack Types
236+
Use `shared.stack` (singular) or `shared.stacks` (plural):
237+
- "CLI" / "CLIs", "Extension" / "Extensions", "IDE" / "IDEs"
238+
- "Model" / "Models", "Model Provider" / "Model Providers", "Vendor" / "Vendors"
239+
240+
### Product Detail Fields
241+
Reference `components.productHero`:
242+
- "Documentation", "Download", "License", "Platforms", "Stars"
243+
- "Vendor", "Version", "Visit Website", "Get API Key"
244+
245+
### Navigation Patterns
246+
Consider parameterization for repeated patterns:
247+
- "Back to X" → "Back to {target}"
248+
- "All X" → "All {items}"
249+
- "View X" → "View {name}"
250+
251+
## Resources
252+
253+
### scripts/analyze-duplicates.mjs
254+
Node.js script that scans English locale files and generates a comprehensive duplication report.
255+
256+
**Features:**
257+
- Recursive JSON file scanning
258+
- Flattens nested objects to dot-notation paths
259+
- Identifies exact and parameterized duplicates
260+
- Detects common patterns (action verbs, navigation, etc.)
261+
- Suggests consolidation targets based on namespace priority
262+
263+
**Usage:** `node .claude/skills/i18n-dedup-optimizer/scripts/analyze-duplicates.mjs`
264+
265+
### references/i18n-structure.md
266+
Comprehensive documentation of the project's i18n structure:
267+
- Directory and namespace organization
268+
- Reference syntax and resolution rules
269+
- Best practices and naming conventions
270+
- Common duplication patterns
271+
- File organization rules
272+
- Complete optimization workflow
273+
274+
Load this reference when needing detailed context about the i18n system structure.
275+
276+
## Best Practices
277+
278+
### Consolidation Priority
279+
1. **`shared` namespace**: Cross-cutting terms used across multiple pages and components
280+
2. **`components` namespace**: Component-specific but reusable UI terms
281+
3. **`pages` namespace**: Page-specific terms that happen to be duplicated
282+
283+
### Safety Guidelines
284+
- Always get user approval before making changes
285+
- Test thoroughly after consolidation
286+
- Maintain consistency across all language files
287+
- Preserve the semantic meaning of translations
288+
- Keep git commits organized by consolidation batch
289+
290+
### Efficiency Tips
291+
- Start with high-impact duplicates (3+ occurrences)
292+
- Consolidate related terms together (e.g., all action verbs at once)
293+
- Use pattern-based consolidation for systematic duplicates
294+
- Run analysis periodically to prevent new duplications

0 commit comments

Comments
 (0)