Skip to content

Commit

Permalink
改進轉化案例
Browse files Browse the repository at this point in the history
  • Loading branch information
igncp committed Jul 1, 2024
1 parent b9467ca commit 0ef7af3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
1 change: 1 addition & 0 deletions docs/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Tasks

- Add a check if anki front is repeated
- Add simplified chinese script
- Pass manager via context
- Persist config in records (which subpanels are displayed)
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 26 additions & 10 deletions src/react-ui/languages/common/conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,28 @@ export const 繁體轉簡體 = 字典
return 累積
}, {})

const 簡體轉繁體例外: Record<string, string | undefined> = {
const sameConversionSet: Set<string> = new Set([
'了',
'出',
'吃',
'合',
'同',
'向',
'回',
'家',
'巨',
'才',
'暗',
'玩',
'真',
'系',
'累',
'致',
'面',
])

const correctConversionObj: Record<string, string | undefined> = {
: '個',
: '了',
: '出',
: '向',
: '回',
: '家',
: '巨',
: '真',
: '致',
}

const 簡體轉繁體 = Object.entries(繁體轉簡體).reduce<
Expand All @@ -55,5 +67,9 @@ export const changeToSimplified = (文字: string) =>
export const changeToTraditional = (文字: string) =>
文字
.split(``)
.map(字元 => 簡體轉繁體例外[字元] ?? 簡體轉繁體[字元] ?? 字元)
.map(字元 => {
if (sameConversionSet.has(字元)) return 字元

return correctConversionObj[字元] ?? 簡體轉繁體[字元] ?? 字元
})
.join('')

0 comments on commit 0ef7af3

Please sign in to comment.