mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-03 06:24:30 +00:00
docs: add paraglide-js i18n rules and usage guide to AGENTS.md
This commit is contained in:
@@ -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')
|
logger.info({ userId: user.id, projectId }, 'Project deleted successfully')
|
||||||
```
|
```
|
||||||
- **Levels**: Use appropriate levels: `debug`, `info`, `warn`, `error`.
|
- **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.
|
||||||
|
|||||||
Reference in New Issue
Block a user