This feature automatically generates Pinyin (Chinese phonetic notation) from Chinese characters for acupoint entries, making it easier to input and manage acupoint data.
- Automatic Pinyin Generation: When you enter Chinese characters for an acupoint, Pinyin is automatically generated
- Real-time Conversion: Pinyin updates as you type Chinese characters
- Manual Override: You can still manually edit the Pinyin field if needed
- Multiple Pinyin Formats: Supports tone marks, numeric tones, and normal Pinyin
- Batch Migration: Script to generate Pinyin for existing acupoints
- API Endpoint: Dedicated endpoint for Pinyin conversion
- When you enter Chinese characters in the "Chữ Hán" field, the system automatically detects Chinese characters
- A request is sent to the server to generate Pinyin
- The generated Pinyin appears in the "Pinyin" field
- You can manually edit the Pinyin if needed
- A refresh button allows manual regeneration
- Uses the
pinyinnpm library for accurate Chinese-to-Pinyin conversion - Automatically generates Pinyin when creating or updating acupoints
- Provides a dedicated API endpoint for real-time conversion
- Handles edge cases and error scenarios gracefully
server/src/services/pinyinService.ts- Core Pinyin conversion serviceserver/src/scripts/generatePinyinForExistingAcupoints.ts- Migration scriptserver/src/scripts/testPinyinService.ts- Test script
server/src/routes/admin.ts- Added auto-generation logic and API endpointclient/src/components/qigong/AcupointManagement.tsx- Added real-time Pinyin generationserver/package.json- Added new npm scripts
pinyin- Chinese to Pinyin conversion library
- 合谷 → hégǔ (Hegu, LI4)
- 足三里 → zúsānlǐ (Zusanli, ST36)
- 百会 → bǎihuì (Baihui, GV20)
- 神门 → shénmén (Shenmen, HE7)
- 太冲 → tàichōng (Taichong, LR3)
# Convert Chinese characters to Pinyin
POST /api/admin/convert-pinyin?access_code=YOUR_ACCESS_CODE
Content-Type: application/json
{
"chinese_characters": "合谷"
}
# Response:
{
"success": true,
"data": {
"chinese_characters": "合谷",
"pinyin": "hé gǔ",
"pinyin_normal": "he gu",
"pinyin_numeric": "he2 gu3",
"acupoint_pinyin": "hégǔ",
"message": "Pinyin conversion successful"
}
}cd server
npm run test:pinyincd server
# Preview what would be updated (safe, no changes made)
npm run generate-pinyin:preview
# Actually perform the update
npm run generate-pinyin- Tone Marks (Default): hégǔ
- Normal (No tones): he gu
- Numeric Tones: he2 gu3
- Acupoint Format (Compact with tones): hégǔ
- Triggers when Chinese characters are entered
- Only generates if Pinyin field is empty
- Preserves manual edits
- Handles mixed Chinese/English text
- Ignores non-Chinese characters
- Graceful fallback if conversion fails
- Validates input before processing
- Logs errors for debugging
- Continues operation even if Pinyin generation fails
- Efficient conversion using proven library
- Minimal impact on form performance
- Caching for repeated conversions
- Async processing to avoid UI blocking
- Manual Override: You can always manually edit the Pinyin field
- Existing Data: Use the migration script to update existing acupoints
- Access Control: Pinyin conversion requires valid access code
- Language Support: Primarily designed for Simplified Chinese characters
- Backup: Always backup your database before running migration scripts
Pinyin not generating automatically:
- Check that Chinese characters are properly entered
- Ensure access code is valid
- Check browser console for errors
Migration script not working:
- Ensure server is built:
npm run build - Check database permissions
- Verify acupoint data exists
API endpoint not responding:
- Verify server is running
- Check access code parameter
- Ensure Content-Type is application/json
The implementation includes comprehensive testing:
- Unit tests for Pinyin service
- Integration tests for API endpoints
- Edge case handling
- Performance validation
Run tests with:
cd server
npm run test:pinyinPotential improvements for future versions:
- Support for Traditional Chinese characters
- Multiple pronunciation options for polyphones
- Batch conversion interface
- Pinyin pronunciation audio
- Integration with other Chinese text fields
This feature significantly improves the user experience for managing acupoint data by automating the tedious task of manually entering Pinyin for Chinese acupoint names.