docs: add paraglide-js i18n rules and usage guide to AGENTS.md

This commit is contained in:
yiling
2026-06-26 10:44:49 +08:00
parent 48f4c83cc8
commit b6ff60f8b8
+48
View File
@@ -408,3 +408,51 @@ We use **pino** for logging. Always use **structured logging** to ensure logs ar
logger.info({ userId: user.id, projectId }, 'Project deleted successfully')
```
- **Levels**: Use appropriate levels: `debug`, `info`, `warn`, `error`.
## Internationalization (i18n)
All user-facing text in the WebUI (`packages/webui`) MUST be internationalized using **Paraglide JS**. Hardcoded text in UI components is strictly forbidden.
### Message Definition
1. Define your English message strings in [packages/webui/messages/en.json](file:///Users/yiling/Projects/shumai/packages/webui/messages/en.json).
2. Define the corresponding Chinese translation strings in [packages/webui/messages/zh.json](file:///Users/yiling/Projects/shumai/packages/webui/messages/zh.json).
3. Keys should use `snake_case`.
Example (`en.json`):
```json
{
"my_key": "My English Text"
}
```
### Compilation
When you add or update translation keys, you must compile them to regenerate the type-safe functions:
```bash
# Compile once (generates type-safe TS/JS functions on disk)
bun run i18n:compile
# Watch and recompile on change during development
bun run i18n:watch
```
### Usage in Components
Import the compiled message namespace `m` and call it as a function:
```typescript
import { m } from '@/ui/src/paraglide/messages.js'
export function MyComponent() {
return (
<div>
<h1>{m.my_key()}</h1>
</div>
)
}
```
Always use the absolute workspace alias path `@/ui/src/paraglide/messages.js` (or `runtime.js` for runtime features) when importing Paraglide outputs.