A Next.js web app that converts Simplified Chinese text files to Traditional Chinese (Taiwan). Supports multiple file formats (.txt, .srt, .csv, .xml) and various Chinese encodings.
- Framework: Next.js 14 (App Router)
- Language: TypeScript
- Database: Supabase (PostgreSQL + Auth)
- Conversion: OpenCC-js (client-side), encoding-japanese (encoding detection)
- Testing: Jest + React Testing Library
- Styling: Tailwind CSS + Material Icons
- Client-side Chinese text conversion (no server upload needed)
- Multi-encoding support: UTF-8, GBK, GB2312, GB18030, Big5
- Custom dictionary for user-defined conversions
- Batch file conversion with progress tracking
# Install dependencies
npm install
# Start dev server
npm run dev
# Run tests
npm test
# Type check
npx tsc --noEmitFor testing logged-in features with Chrome MCP without real authentication:
-
Add to
.env:ENABLE_TEST_LOGIN=true -
Start dev server:
npm run dev
Login as test user:
navigate_page → http://localhost:3000/api/dev/test-login
This will:
- Set test session cookie with mock user ID
- UI shows logged-in state (email
test@txtconv.localin header) - Custom dictionary section shows "PRO" badge with "10,000 組對照" limit
- Dictionary editor is enabled (can edit, import, export)
- Lifetime plan shows as "目前方案" (current plan)
- Pre-load custom dictionary (10 entries that differ from OpenCC defaults)
Logout:
navigate_page → http://localhost:3000/api/dev/test-logout
This will:
- Clear test session cookie
- UI returns to guest state ("Login" button in header)
- Custom dictionary shows "GUEST" badge with "5 組對照" limit
- Dictionary editor is disabled
The test user has custom dictionary entries that differ from OpenCC defaults:
| Input (Simplified) | Custom Dict Output | OpenCC Default |
|---|---|---|
| 软件测试 | 軟體程式測試 | 軟體測試 |
| 硬件设备 | 硬體裝置設備 | 硬體裝置 |
| 网络信息 | 網際網路訊息通知 | 網路資訊 |
If you see the "Custom Dict Output", custom dictionary is working. If you see "OpenCC Default", custom dictionary is NOT being applied.
- Test login only works when
NODE_ENV !== 'production' - Requires explicit
ENABLE_TEST_LOGIN=truein environment - Never deployed to production
| Path | Purpose |
|---|---|
lib/client-converter.ts |
Client-side conversion logic |
lib/custom-dict.ts |
Custom dictionary parsing and application |
lib/test-user.ts |
Test user constants for dev testing |
lib/actions/auth.ts |
Server-side auth with test session detection |
components/FileUpload.tsx |
Main file upload and conversion UI |
app/api/dev/test-login/route.ts |
Dev-only test login endpoint |
app/api/dev/test-logout/route.ts |
Dev-only test logout endpoint |
The app detects file encoding automatically using a scoring heuristic:
- Try UTF-8 with strict mode
- Try GBK, GB18030, Big5 and score results
- Pick encoding with highest "Chinese-ness" score
- Fall back to encoding-japanese for Japanese encodings
Important: GBK and Big5 can decode each other's bytes without errors but produce wrong characters. The scoring heuristic (calculateChineseScore) distinguishes them by checking for valid CJK character patterns.
# Run all tests
npm test
# Run specific test file
npx jest __tests__/lib/client-converter.test.ts --verbose
# Run with coverage
npx jest --coverage__tests__/lib/client-converter.test.ts- Encoding detection, custom dict integration__tests__/lib/custom-dict.test.ts- Dictionary parsing and validation__tests__/lib/encoding.test.ts- Server-side encoding utilities__tests__/components/FileUpload.test.tsx- UI component tests
- Use Chrome MCP to navigate to the app
- Upload test files from
/tmp/or create with specific encoding - Verify converted output matches expected Traditional Chinese
- Login via
/api/dev/test-login - Upload file containing
软件测试 - Expected output:
軟體程式測試(not軟體測試)
- Check browser console for detected encoding
- The
readFileWithEncodingfunction logs encoding scores - Compare scores between GBK and Big5 for ambiguous files