@qazuor/claude-code-config 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1248 -0
- package/dist/bin.cjs +11886 -0
- package/dist/bin.cjs.map +1 -0
- package/dist/bin.d.cts +1 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +11869 -0
- package/dist/bin.js.map +1 -0
- package/dist/index.cjs +3887 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1325 -0
- package/dist/index.d.ts +1325 -0
- package/dist/index.js +3835 -0
- package/dist/index.js.map +1 -0
- package/package.json +86 -0
- package/templates/.log/notifications.log +1775 -0
- package/templates/agents/README.md +164 -0
- package/templates/agents/_registry.json +443 -0
- package/templates/agents/design/content-writer.md +353 -0
- package/templates/agents/design/ux-ui-designer.md +382 -0
- package/templates/agents/engineering/astro-engineer.md +293 -0
- package/templates/agents/engineering/db-drizzle-engineer.md +360 -0
- package/templates/agents/engineering/express-engineer.md +316 -0
- package/templates/agents/engineering/fastify-engineer.md +399 -0
- package/templates/agents/engineering/hono-engineer.md +263 -0
- package/templates/agents/engineering/mongoose-engineer.md +473 -0
- package/templates/agents/engineering/nestjs-engineer.md +429 -0
- package/templates/agents/engineering/nextjs-engineer.md +451 -0
- package/templates/agents/engineering/node-typescript-engineer.md +347 -0
- package/templates/agents/engineering/prisma-engineer.md +432 -0
- package/templates/agents/engineering/react-senior-dev.md +394 -0
- package/templates/agents/engineering/tanstack-start-engineer.md +447 -0
- package/templates/agents/engineering/tech-lead.md +269 -0
- package/templates/agents/product/product-functional.md +329 -0
- package/templates/agents/product/product-technical.md +578 -0
- package/templates/agents/quality/debugger.md +514 -0
- package/templates/agents/quality/qa-engineer.md +390 -0
- package/templates/agents/specialized/enrichment-agent.md +277 -0
- package/templates/agents/specialized/i18n-specialist.md +322 -0
- package/templates/agents/specialized/seo-ai-specialist.md +387 -0
- package/templates/agents/specialized/tech-writer.md +300 -0
- package/templates/code-style/.editorconfig +27 -0
- package/templates/code-style/.prettierignore +25 -0
- package/templates/code-style/.prettierrc +12 -0
- package/templates/code-style/biome.json +78 -0
- package/templates/code-style/commitlint.config.js +44 -0
- package/templates/commands/README.md +175 -0
- package/templates/commands/_registry.json +420 -0
- package/templates/commands/add-new-entity.md +211 -0
- package/templates/commands/audit/accessibility-audit.md +360 -0
- package/templates/commands/audit/performance-audit.md +290 -0
- package/templates/commands/audit/security-audit.md +231 -0
- package/templates/commands/code-check.md +127 -0
- package/templates/commands/five-why.md +225 -0
- package/templates/commands/formatting/format-markdown.md +197 -0
- package/templates/commands/git/commit.md +247 -0
- package/templates/commands/meta/create-agent.md +257 -0
- package/templates/commands/meta/create-command.md +312 -0
- package/templates/commands/meta/create-skill.md +321 -0
- package/templates/commands/meta/help.md +318 -0
- package/templates/commands/planning/check-completed-tasks.md +224 -0
- package/templates/commands/planning/cleanup-issues.md +248 -0
- package/templates/commands/planning/planning-cleanup.md +251 -0
- package/templates/commands/planning/sync-planning-github.md +133 -0
- package/templates/commands/planning/sync-todos-github.md +203 -0
- package/templates/commands/quality-check.md +211 -0
- package/templates/commands/run-tests.md +159 -0
- package/templates/commands/start-feature-plan.md +232 -0
- package/templates/commands/start-refactor-plan.md +244 -0
- package/templates/commands/sync-planning.md +176 -0
- package/templates/commands/update-docs.md +242 -0
- package/templates/docs/CHECKPOINT-SYSTEM.md +504 -0
- package/templates/docs/INDEX.md +677 -0
- package/templates/docs/RECOMMENDED-HOOKS.md +415 -0
- package/templates/docs/_registry.json +329 -0
- package/templates/docs/diagrams/README.md +220 -0
- package/templates/docs/diagrams/agent-hierarchy.mmd +55 -0
- package/templates/docs/diagrams/documentation-map.mmd +61 -0
- package/templates/docs/diagrams/tools-relationship.mmd +55 -0
- package/templates/docs/diagrams/workflow-decision-tree.mmd +38 -0
- package/templates/docs/doc-sync.md +533 -0
- package/templates/docs/examples/end-to-end-workflow.md +1505 -0
- package/templates/docs/glossary.md +495 -0
- package/templates/docs/guides/mockup-prompt-engineering.md +644 -0
- package/templates/docs/guides/mockup-setup.md +737 -0
- package/templates/docs/learnings/README.md +250 -0
- package/templates/docs/learnings/common-architectural-patterns.md +123 -0
- package/templates/docs/learnings/common-mistakes-to-avoid.md +149 -0
- package/templates/docs/learnings/markdown-formatting-standards.md +104 -0
- package/templates/docs/learnings/monorepo-command-execution.md +64 -0
- package/templates/docs/learnings/optimization-tips.md +146 -0
- package/templates/docs/learnings/planning-linear-sync-workflow.md +70 -0
- package/templates/docs/learnings/shell-compatibility-fish.md +46 -0
- package/templates/docs/learnings/test-organization-structure.md +68 -0
- package/templates/docs/mcp-installation.md +613 -0
- package/templates/docs/mcp-servers.md +989 -0
- package/templates/docs/notification-installation.md +570 -0
- package/templates/docs/quick-start.md +354 -0
- package/templates/docs/standards/architecture-patterns.md +1064 -0
- package/templates/docs/standards/atomic-commits.md +513 -0
- package/templates/docs/standards/code-standards.md +993 -0
- package/templates/docs/standards/design-standards.md +656 -0
- package/templates/docs/standards/documentation-standards.md +1160 -0
- package/templates/docs/standards/testing-standards.md +969 -0
- package/templates/docs/system-maintenance.md +604 -0
- package/templates/docs/templates/PDR-template.md +561 -0
- package/templates/docs/templates/TODOs-template.md +534 -0
- package/templates/docs/templates/tech-analysis-template.md +800 -0
- package/templates/docs/workflows/README.md +519 -0
- package/templates/docs/workflows/atomic-task-protocol.md +955 -0
- package/templates/docs/workflows/decision-tree.md +482 -0
- package/templates/docs/workflows/edge-cases.md +856 -0
- package/templates/docs/workflows/phase-1-planning.md +957 -0
- package/templates/docs/workflows/phase-2-implementation.md +896 -0
- package/templates/docs/workflows/phase-3-validation.md +792 -0
- package/templates/docs/workflows/phase-4-finalization.md +927 -0
- package/templates/docs/workflows/quick-fix-protocol.md +505 -0
- package/templates/docs/workflows/task-atomization.md +537 -0
- package/templates/docs/workflows/task-completion-protocol.md +448 -0
- package/templates/hooks/on-notification.sh +28 -0
- package/templates/schemas/checkpoint.schema.json +97 -0
- package/templates/schemas/code-registry.schema.json +84 -0
- package/templates/schemas/pdr.schema.json +314 -0
- package/templates/schemas/problems.schema.json +55 -0
- package/templates/schemas/tech-analysis.schema.json +404 -0
- package/templates/schemas/telemetry.schema.json +298 -0
- package/templates/schemas/todos.schema.json +234 -0
- package/templates/schemas/workflows.schema.json +69 -0
- package/templates/scripts/add-changelogs.sh +105 -0
- package/templates/scripts/generate-code-registry.ts +270 -0
- package/templates/scripts/health-check.sh +343 -0
- package/templates/scripts/sync-registry.sh +40 -0
- package/templates/scripts/telemetry-report.ts +36 -0
- package/templates/scripts/validate-docs.sh +224 -0
- package/templates/scripts/validate-registry.sh +225 -0
- package/templates/scripts/validate-schemas.ts +283 -0
- package/templates/scripts/validate-structure.sh +165 -0
- package/templates/scripts/worktree-cleanup.sh +81 -0
- package/templates/scripts/worktree-create.sh +63 -0
- package/templates/sessions/planning/.gitkeep +0 -0
- package/templates/sessions/planning/archived/.gitkeep +0 -0
- package/templates/settings.json +202 -0
- package/templates/settings.local.json +138 -0
- package/templates/skills/README.md +197 -0
- package/templates/skills/_registry.json +473 -0
- package/templates/skills/audit/accessibility-audit.md +309 -0
- package/templates/skills/audit/performance-audit.md +257 -0
- package/templates/skills/audit/security-audit.md +217 -0
- package/templates/skills/auth/nextauth-patterns.md +308 -0
- package/templates/skills/brand-guidelines.md +240 -0
- package/templates/skills/documentation/markdown-formatter.md +302 -0
- package/templates/skills/git/git-commit-helper.md +321 -0
- package/templates/skills/i18n/i18n-patterns.md +251 -0
- package/templates/skills/patterns/error-handling-patterns.md +242 -0
- package/templates/skills/patterns/tdd-methodology.md +342 -0
- package/templates/skills/qa/qa-criteria-validator.md +383 -0
- package/templates/skills/qa/web-app-testing.md +398 -0
- package/templates/skills/react/react-hook-form-patterns.md +359 -0
- package/templates/skills/state/redux-toolkit-patterns.md +272 -0
- package/templates/skills/state/tanstack-query-patterns.md +299 -0
- package/templates/skills/state/zustand-patterns.md +301 -0
- package/templates/skills/tech/mermaid-diagram-specialist.md +195 -0
- package/templates/skills/tech/shadcn-specialist.md +252 -0
- package/templates/skills/tech/vercel-specialist.md +297 -0
- package/templates/skills/testing/api-app-testing.md +254 -0
- package/templates/skills/testing/performance-testing.md +275 -0
- package/templates/skills/testing/security-testing.md +348 -0
- package/templates/skills/utils/add-memory.md +295 -0
- package/templates/skills/utils/json-data-auditor.md +283 -0
- package/templates/skills/utils/pdf-creator-editor.md +342 -0
- package/templates/tools/format-markdown.sh +185 -0
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: git-commit-helper
|
|
3
|
+
category: git
|
|
4
|
+
description: Generate conventional commit messages and group changes logically for clean git history
|
|
5
|
+
usage: When preparing commits, analyzing changes, or creating commit messages
|
|
6
|
+
input: Changed files, git status, commit context
|
|
7
|
+
output: Conventional commit messages and copy-paste ready git commands
|
|
8
|
+
config_required:
|
|
9
|
+
- commit_convention: "Commit message convention (conventional-commits, gitmoji)"
|
|
10
|
+
- allowed_types: "List of allowed commit types"
|
|
11
|
+
- allowed_scopes: "List of allowed scopes"
|
|
12
|
+
- subject_max_length: "Maximum subject line length"
|
|
13
|
+
- require_body: "Whether commit body is required"
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
# Git Commit Helper
|
|
17
|
+
|
|
18
|
+
## ⚙️ Configuration
|
|
19
|
+
|
|
20
|
+
| Setting | Description | Example |
|
|
21
|
+
|---------|-------------|---------|
|
|
22
|
+
| `commit_convention` | Message format | `conventional-commits`, `gitmoji` |
|
|
23
|
+
| `allowed_types` | Commit types | `feat`, `fix`, `docs`, `refactor`, etc. |
|
|
24
|
+
| `allowed_scopes` | Scope options | `api`, `db`, `web`, `admin`, `components` |
|
|
25
|
+
| `subject_max_length` | Max subject chars | `72` |
|
|
26
|
+
| `require_body` | Body required | `false` for simple changes |
|
|
27
|
+
| `breaking_change_prefix` | Breaking change format | `BREAKING CHANGE:` |
|
|
28
|
+
|
|
29
|
+
## Purpose
|
|
30
|
+
|
|
31
|
+
Generate conventional commit messages that follow standards, analyze changed files, group changes logically, and provide copy-paste ready commands.
|
|
32
|
+
|
|
33
|
+
## Commit Format
|
|
34
|
+
|
|
35
|
+
```text
|
|
36
|
+
{type}({scope}): {subject}
|
|
37
|
+
|
|
38
|
+
{body}
|
|
39
|
+
|
|
40
|
+
{footer}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Components:**
|
|
44
|
+
- **type**: Category (required)
|
|
45
|
+
- **scope**: Area affected (optional)
|
|
46
|
+
- **subject**: Short summary (required, ≤ 72 chars)
|
|
47
|
+
- **body**: Details (optional)
|
|
48
|
+
- **footer**: Breaking changes, issues (optional)
|
|
49
|
+
|
|
50
|
+
## Commit Types
|
|
51
|
+
|
|
52
|
+
| Type | Purpose | Example |
|
|
53
|
+
|------|---------|---------|
|
|
54
|
+
| `feat` | New feature | `feat(api): add user search endpoint` |
|
|
55
|
+
| `fix` | Bug fix | `fix(auth): correct token expiration` |
|
|
56
|
+
| `docs` | Documentation | `docs(api): update endpoint docs` |
|
|
57
|
+
| `style` | Formatting | `style: format with prettier` |
|
|
58
|
+
| `refactor` | Code refactor | `refactor(service): extract validation` |
|
|
59
|
+
| `perf` | Performance | `perf(query): add database indexes` |
|
|
60
|
+
| `test` | Tests | `test(api): add integration tests` |
|
|
61
|
+
| `build` | Build system | `build: update dependencies` |
|
|
62
|
+
| `ci` | CI/CD | `ci: add E2E test workflow` |
|
|
63
|
+
| `chore` | Maintenance | `chore: update eslint config` |
|
|
64
|
+
|
|
65
|
+
## Scopes
|
|
66
|
+
|
|
67
|
+
### Backend
|
|
68
|
+
|
|
69
|
+
```text
|
|
70
|
+
api - API routes
|
|
71
|
+
db - Database/schemas
|
|
72
|
+
services - Business logic
|
|
73
|
+
auth - Authentication
|
|
74
|
+
validation - Input validation
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Frontend
|
|
78
|
+
|
|
79
|
+
```text
|
|
80
|
+
web - Web application
|
|
81
|
+
admin - Admin dashboard
|
|
82
|
+
components - React components
|
|
83
|
+
hooks - Custom hooks
|
|
84
|
+
ui - UI components
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Cross-cutting
|
|
88
|
+
|
|
89
|
+
```text
|
|
90
|
+
types - TypeScript types
|
|
91
|
+
schemas - Validation schemas
|
|
92
|
+
config - Configuration
|
|
93
|
+
deps - Dependencies
|
|
94
|
+
docs - Documentation
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Message Guidelines
|
|
98
|
+
|
|
99
|
+
### Subject Line
|
|
100
|
+
|
|
101
|
+
✅ **Good:**
|
|
102
|
+
```text
|
|
103
|
+
feat(search): add full-text search
|
|
104
|
+
fix(pricing): handle zero price edge case
|
|
105
|
+
refactor(models): simplify base interface
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
❌ **Bad:**
|
|
109
|
+
```text
|
|
110
|
+
feat: added some stuff
|
|
111
|
+
FIX - bug
|
|
112
|
+
Refactoring things
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Rules:**
|
|
116
|
+
- Imperative mood ("add" not "added")
|
|
117
|
+
- Lowercase first letter
|
|
118
|
+
- No period at end
|
|
119
|
+
- Max configured length
|
|
120
|
+
- Specific and descriptive
|
|
121
|
+
|
|
122
|
+
### Body
|
|
123
|
+
|
|
124
|
+
✅ **Good:**
|
|
125
|
+
```text
|
|
126
|
+
fix(booking): prevent double booking
|
|
127
|
+
|
|
128
|
+
Check availability before creating booking by:
|
|
129
|
+
- Querying existing bookings for date range
|
|
130
|
+
- Ensuring no overlap with dates
|
|
131
|
+
- Adding unique constraint
|
|
132
|
+
- Returning clear error message
|
|
133
|
+
|
|
134
|
+
Prevents race conditions.
|
|
135
|
+
|
|
136
|
+
Fixes #156
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
**Rules:**
|
|
140
|
+
- Explain **why**, not just **what**
|
|
141
|
+
- Use bullet points for multiple changes
|
|
142
|
+
- Wrap at 72 characters
|
|
143
|
+
- Separate paragraphs with blank lines
|
|
144
|
+
|
|
145
|
+
## Grouping Changes
|
|
146
|
+
|
|
147
|
+
### Strategy
|
|
148
|
+
|
|
149
|
+
Group by logical units:
|
|
150
|
+
- One feature per commit
|
|
151
|
+
- One bug fix per commit
|
|
152
|
+
- Related changes together
|
|
153
|
+
|
|
154
|
+
### Example: Feature Development
|
|
155
|
+
|
|
156
|
+
Instead of one large commit:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
# ❌ Bad: Everything together
|
|
160
|
+
git add .
|
|
161
|
+
git commit -m "feat: add booking feature"
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Split logically:
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
# ✅ Good: Separate commits
|
|
168
|
+
|
|
169
|
+
# 1. Database schema
|
|
170
|
+
git add packages/db/src/schemas/booking/
|
|
171
|
+
git commit -m "feat(db): add booking schema
|
|
172
|
+
|
|
173
|
+
- Define table structure
|
|
174
|
+
- Add relationships
|
|
175
|
+
- Create indexes"
|
|
176
|
+
|
|
177
|
+
# 2. Service layer
|
|
178
|
+
git add packages/services/src/booking/
|
|
179
|
+
git commit -m "feat(services): implement booking service
|
|
180
|
+
|
|
181
|
+
- Add CRUD operations
|
|
182
|
+
- Implement validation
|
|
183
|
+
- Add tests (95% coverage)"
|
|
184
|
+
|
|
185
|
+
# 3. API routes
|
|
186
|
+
git add apps/api/src/routes/bookings/
|
|
187
|
+
git commit -m "feat(api): add booking endpoints
|
|
188
|
+
|
|
189
|
+
- POST /bookings - Create
|
|
190
|
+
- GET /bookings/:id - Details
|
|
191
|
+
- Add authentication"
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Workflow
|
|
195
|
+
|
|
196
|
+
### 1. Check Status
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
git status
|
|
200
|
+
git diff --stat
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### 2. Analyze Changes
|
|
204
|
+
|
|
205
|
+
Identify changed areas:
|
|
206
|
+
- Backend: API, services, models
|
|
207
|
+
- Frontend: components, pages
|
|
208
|
+
- Shared: schemas, types
|
|
209
|
+
- Infrastructure: CI, config
|
|
210
|
+
|
|
211
|
+
### 3. Group Related
|
|
212
|
+
|
|
213
|
+
Group by:
|
|
214
|
+
- Same feature
|
|
215
|
+
- Same bug fix
|
|
216
|
+
- Same refactoring
|
|
217
|
+
|
|
218
|
+
### 4. Stage & Commit
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
# Stage specific files
|
|
222
|
+
git add path/to/file1 path/to/file2
|
|
223
|
+
|
|
224
|
+
# Create commit
|
|
225
|
+
git commit -m "feat(scope): subject
|
|
226
|
+
|
|
227
|
+
Body explaining changes
|
|
228
|
+
|
|
229
|
+
Closes #123"
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Copy-Paste Template
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
# === Commit 1: Database Schema ===
|
|
236
|
+
git add packages/db/src/schemas/resource/
|
|
237
|
+
git commit -m "feat(db): add resource schema
|
|
238
|
+
|
|
239
|
+
- Define table with required fields
|
|
240
|
+
- Add foreign key relationships
|
|
241
|
+
- Create indexes for queries"
|
|
242
|
+
|
|
243
|
+
# === Commit 2: Service Layer ===
|
|
244
|
+
git add packages/services/src/resource/
|
|
245
|
+
git commit -m "feat(services): implement resource service
|
|
246
|
+
|
|
247
|
+
- Add CRUD operations
|
|
248
|
+
- Implement validation logic
|
|
249
|
+
- Add 95% test coverage"
|
|
250
|
+
|
|
251
|
+
# === Commit 3: API Endpoints ===
|
|
252
|
+
git add apps/api/src/routes/resources/
|
|
253
|
+
git commit -m "feat(api): add resource endpoints
|
|
254
|
+
|
|
255
|
+
- POST /resources - Create
|
|
256
|
+
- GET /resources - List
|
|
257
|
+
- GET /resources/:id - Details
|
|
258
|
+
- Add authentication"
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## Common Scenarios
|
|
262
|
+
|
|
263
|
+
### Bug Fix
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
git add src/utils/calculator.ts src/utils/calculator.test.ts
|
|
267
|
+
git commit -m "fix(pricing): correct weekend surcharge
|
|
268
|
+
|
|
269
|
+
Weekend check was using incorrect day values.
|
|
270
|
+
Changed to check day === 0 (Sunday) or day === 6 (Saturday).
|
|
271
|
+
|
|
272
|
+
Added tests for all weekdays to prevent regression.
|
|
273
|
+
|
|
274
|
+
Fixes #123"
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Refactoring
|
|
278
|
+
|
|
279
|
+
```bash
|
|
280
|
+
git add src/services/*/validation.ts
|
|
281
|
+
git commit -m "refactor(services): extract validation logic
|
|
282
|
+
|
|
283
|
+
- Create shared ValidationService
|
|
284
|
+
- Remove duplicate validation code
|
|
285
|
+
- Update services to use shared validator
|
|
286
|
+
- No behavior changes"
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Breaking Change
|
|
290
|
+
|
|
291
|
+
```bash
|
|
292
|
+
git commit -m "feat(api): change response format
|
|
293
|
+
|
|
294
|
+
BREAKING CHANGE: API now returns ISO 8601 dates.
|
|
295
|
+
Clients must update date parsing logic.
|
|
296
|
+
|
|
297
|
+
Migration guide: docs/migrations/v2.md"
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
## Best Practices
|
|
301
|
+
|
|
302
|
+
| Practice | Description |
|
|
303
|
+
|----------|-------------|
|
|
304
|
+
| **Atomic** | One logical change per commit |
|
|
305
|
+
| **Present Tense** | "add" not "added" |
|
|
306
|
+
| **Explain Why** | Body explains reasoning |
|
|
307
|
+
| **Reference Issues** | Use "Fixes #123", "Closes #456" |
|
|
308
|
+
| **Verify** | Check `git log -1` before push |
|
|
309
|
+
| **Test** | Ensure tests pass before commit |
|
|
310
|
+
|
|
311
|
+
## Checklist
|
|
312
|
+
|
|
313
|
+
- [ ] Changes grouped logically
|
|
314
|
+
- [ ] Commit type appropriate
|
|
315
|
+
- [ ] Scope accurate
|
|
316
|
+
- [ ] Subject clear and concise
|
|
317
|
+
- [ ] Body explains why (if needed)
|
|
318
|
+
- [ ] Issues referenced
|
|
319
|
+
- [ ] Tests passing
|
|
320
|
+
- [ ] No debug code or TODOs
|
|
321
|
+
- [ ] Breaking changes documented
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: i18n-patterns
|
|
3
|
+
category: i18n
|
|
4
|
+
description: Internationalization patterns for React and Next.js applications
|
|
5
|
+
usage: Use when implementing multi-language support, locale routing, and content translation
|
|
6
|
+
input: Supported locales, default locale, translation keys
|
|
7
|
+
output: i18n configuration, translation files, locale-aware components
|
|
8
|
+
config_required:
|
|
9
|
+
i18n_library: "i18n library being used"
|
|
10
|
+
supported_locales: "List of supported locale codes"
|
|
11
|
+
default_locale: "Default/fallback locale"
|
|
12
|
+
locale_routing: "Locale routing strategy"
|
|
13
|
+
rtl_locales: "Right-to-left language locales"
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
# i18n Patterns
|
|
17
|
+
|
|
18
|
+
## ⚙️ Configuration
|
|
19
|
+
|
|
20
|
+
| Setting | Description | Example |
|
|
21
|
+
|---------|-------------|---------|
|
|
22
|
+
| `i18n_library` | Internationalization library | next-intl, react-i18next, i18next |
|
|
23
|
+
| `supported_locales` | Supported locale codes | `['en', 'es', 'fr', 'de']` |
|
|
24
|
+
| `default_locale` | Default/fallback locale | `'en'` |
|
|
25
|
+
| `locale_routing` | URL locale prefix strategy | `'as-needed'`, `'always'`, `'never'` |
|
|
26
|
+
| `rtl_locales` | Right-to-left locales | `['ar', 'he', 'fa']` |
|
|
27
|
+
|
|
28
|
+
## Purpose
|
|
29
|
+
|
|
30
|
+
Implement internationalization with:
|
|
31
|
+
- Locale detection and routing
|
|
32
|
+
- Type-safe translation keys
|
|
33
|
+
- Pluralization and formatting
|
|
34
|
+
- Date, number, and currency formatting
|
|
35
|
+
- RTL language support
|
|
36
|
+
|
|
37
|
+
## Core Setup
|
|
38
|
+
|
|
39
|
+
### Configuration (Next.js)
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
// i18n.ts
|
|
43
|
+
import { getRequestConfig } from 'next-intl/server';
|
|
44
|
+
|
|
45
|
+
export const locales = ['en', 'es', 'fr'] as const;
|
|
46
|
+
export type Locale = (typeof locales)[number];
|
|
47
|
+
export const defaultLocale: Locale = 'en';
|
|
48
|
+
|
|
49
|
+
export default getRequestConfig(async ({ locale }) => {
|
|
50
|
+
if (!locales.includes(locale as Locale)) notFound();
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
messages: (await import(`./messages/${locale}.json`)).default,
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Middleware
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
// middleware.ts
|
|
62
|
+
import createMiddleware from 'next-intl/middleware';
|
|
63
|
+
import { locales, defaultLocale } from './i18n';
|
|
64
|
+
|
|
65
|
+
export default createMiddleware({
|
|
66
|
+
locales,
|
|
67
|
+
defaultLocale,
|
|
68
|
+
localePrefix: 'as-needed', // or 'always' | 'never'
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
export const config = {
|
|
72
|
+
matcher: ['/((?!api|_next|_vercel|.*\\..*).*)'],
|
|
73
|
+
};
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Translation Files
|
|
77
|
+
|
|
78
|
+
### Structure
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
// messages/en.json
|
|
82
|
+
{
|
|
83
|
+
"common": {
|
|
84
|
+
"welcome": "Welcome, {name}!",
|
|
85
|
+
"items": "{count, plural, =0 {No items} =1 {One item} other {# items}}"
|
|
86
|
+
},
|
|
87
|
+
"navigation": {
|
|
88
|
+
"home": "Home",
|
|
89
|
+
"about": "About"
|
|
90
|
+
},
|
|
91
|
+
"forms": {
|
|
92
|
+
"validation": {
|
|
93
|
+
"required": "This field is required",
|
|
94
|
+
"email": "Invalid email address"
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Type Safety
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
// types/i18n.d.ts
|
|
104
|
+
import en from '../messages/en.json';
|
|
105
|
+
|
|
106
|
+
type Messages = typeof en;
|
|
107
|
+
|
|
108
|
+
declare global {
|
|
109
|
+
interface IntlMessages extends Messages {}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Component Usage
|
|
114
|
+
|
|
115
|
+
### Server Components
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
import { useTranslations } from 'next-intl';
|
|
119
|
+
import { getTranslations } from 'next-intl/server';
|
|
120
|
+
|
|
121
|
+
export default function HomePage() {
|
|
122
|
+
const t = useTranslations('common');
|
|
123
|
+
return <h1>{t('welcome', { name: 'John' })}</h1>;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Metadata
|
|
127
|
+
export async function generateMetadata({ params: { locale } }) {
|
|
128
|
+
const t = await getTranslations({ locale, namespace: 'metadata' });
|
|
129
|
+
return {
|
|
130
|
+
title: t('title'),
|
|
131
|
+
description: t('description'),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Client Components
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
'use client';
|
|
140
|
+
import { useTranslations, useLocale } from 'next-intl';
|
|
141
|
+
import { useRouter, usePathname } from 'next/navigation';
|
|
142
|
+
|
|
143
|
+
export function LanguageSwitcher() {
|
|
144
|
+
const locale = useLocale();
|
|
145
|
+
const router = useRouter();
|
|
146
|
+
const pathname = usePathname();
|
|
147
|
+
|
|
148
|
+
const switchLocale = (newLocale: string) => {
|
|
149
|
+
const newPath = pathname.replace(`/${locale}`, `/${newLocale}`);
|
|
150
|
+
router.push(newPath);
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
return (
|
|
154
|
+
<select value={locale} onChange={(e) => switchLocale(e.target.value)}>
|
|
155
|
+
<option value="en">English</option>
|
|
156
|
+
<option value="es">Español</option>
|
|
157
|
+
<option value="fr">Français</option>
|
|
158
|
+
</select>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Formatting
|
|
164
|
+
|
|
165
|
+
### Dates and Numbers
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
import { useFormatter } from 'next-intl';
|
|
169
|
+
|
|
170
|
+
function FormattedContent({ date, amount, currency }: Props) {
|
|
171
|
+
const format = useFormatter();
|
|
172
|
+
|
|
173
|
+
return (
|
|
174
|
+
<div>
|
|
175
|
+
{/* Date */}
|
|
176
|
+
<p>{format.dateTime(date, { dateStyle: 'full' })}</p>
|
|
177
|
+
|
|
178
|
+
{/* Relative time */}
|
|
179
|
+
<p>{format.relativeTime(date)}</p>
|
|
180
|
+
|
|
181
|
+
{/* Currency */}
|
|
182
|
+
<p>{format.number(amount, { style: 'currency', currency })}</p>
|
|
183
|
+
|
|
184
|
+
{/* Percentage */}
|
|
185
|
+
<p>{format.number(0.15, { style: 'percent' })}</p>
|
|
186
|
+
|
|
187
|
+
{/* List */}
|
|
188
|
+
<p>{format.list(['Alice', 'Bob', 'Charlie'], { type: 'conjunction' })}</p>
|
|
189
|
+
</div>
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## RTL Support
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
const rtlLocales = ['ar', 'he', 'fa'];
|
|
198
|
+
|
|
199
|
+
export function RTLProvider({ children }: { children: React.ReactNode }) {
|
|
200
|
+
const locale = useLocale();
|
|
201
|
+
const isRTL = rtlLocales.includes(locale);
|
|
202
|
+
|
|
203
|
+
return <div dir={isRTL ? 'rtl' : 'ltr'}>{children}</div>;
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Translation Key Organization
|
|
208
|
+
|
|
209
|
+
| Category | Purpose | Example Keys |
|
|
210
|
+
|----------|---------|--------------|
|
|
211
|
+
| `common` | Shared translations | `welcome`, `items`, `loading` |
|
|
212
|
+
| `navigation` | Nav items | `home`, `about`, `contact` |
|
|
213
|
+
| `forms` | Form labels/validation | `validation.required`, `validation.email` |
|
|
214
|
+
| `actions` | Button/action labels | `save`, `cancel`, `delete`, `confirm` |
|
|
215
|
+
| `pages` | Page-specific content | `home.title`, `about.description` |
|
|
216
|
+
| `errors` | Error messages | `notFound`, `serverError` |
|
|
217
|
+
|
|
218
|
+
## Best Practices
|
|
219
|
+
|
|
220
|
+
| Practice | Description |
|
|
221
|
+
|----------|-------------|
|
|
222
|
+
| **Namespace Keys** | Use hierarchical namespacing for organization |
|
|
223
|
+
| **Fallback Locale** | Always provide default/fallback language |
|
|
224
|
+
| **Type Safety** | Use TypeScript for translation key validation |
|
|
225
|
+
| **Lazy Loading** | Load translations on demand for performance |
|
|
226
|
+
| **RTL Support** | Support right-to-left languages if needed |
|
|
227
|
+
| **Built-in Formatters** | Use library formatters for dates, numbers, currency |
|
|
228
|
+
| **Context for Translators** | Add comments in translation files for context |
|
|
229
|
+
| **Pluralization** | Use ICU message format for pluralization |
|
|
230
|
+
|
|
231
|
+
## Pluralization Examples
|
|
232
|
+
|
|
233
|
+
```json
|
|
234
|
+
{
|
|
235
|
+
"items": "{count, plural, =0 {No items} =1 {One item} other {# items}}",
|
|
236
|
+
"minutes": "{value, plural, =0 {just now} =1 {1 minute ago} other {# minutes ago}}"
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## When to Use
|
|
241
|
+
|
|
242
|
+
- Multi-language applications
|
|
243
|
+
- Global user bases
|
|
244
|
+
- E-commerce with multiple markets
|
|
245
|
+
- Content-heavy applications
|
|
246
|
+
- Applications requiring RTL support
|
|
247
|
+
|
|
248
|
+
## Related Skills
|
|
249
|
+
|
|
250
|
+
- `brand-guidelines` - Maintain brand voice across locales
|
|
251
|
+
- `web-app-testing` - Test i18n implementations
|