-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(synced-lyrics): Add Simplified/Traditional Chinese converter and improve Romanization to display tone #4111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
6b38e36
d16a516
3c98be3
ae9640b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,10 +3,11 @@ import KuromojiAnalyzer from 'kuroshiro-analyzer-kuromoji'; | |||||||||
| import Kuroshiro from 'kuroshiro'; | ||||||||||
| import { romanize as esHangulRomanize } from 'es-hangul'; | ||||||||||
| import hanja from 'hanja'; | ||||||||||
| import * as pinyin from 'tiny-pinyin'; | ||||||||||
| import { pinyin } from 'pinyin-pro'; | ||||||||||
| import { romanize as romanizeThaiFrag } from '@dehoist/romanize-thai'; | ||||||||||
| import { lazy } from 'lazy-var'; | ||||||||||
| import { detect } from 'tinyld'; | ||||||||||
| import { sify, tify } from 'chinese-conv'; | ||||||||||
|
|
||||||||||
| import { waitForElement } from '@/utils/wait-for-element'; | ||||||||||
| import { LyricsRenderer, setIsVisible } from './renderer'; | ||||||||||
|
|
@@ -84,6 +85,22 @@ export const canonicalize = (text: string) => { | |||||||||
| ); | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| export const convertChineseCharacter = ( | ||||||||||
| text: string, | ||||||||||
| mode: 'simplifiedToTraditional' | 'traditionalToSimplified', | ||||||||||
| ) => { | ||||||||||
| if (!hasChinese([text])) return text; | ||||||||||
|
|
||||||||||
| switch (mode) { | ||||||||||
| case 'simplifiedToTraditional': | ||||||||||
| return tify(text); | ||||||||||
| case 'traditionalToSimplified': | ||||||||||
| return sify(text); | ||||||||||
| default: | ||||||||||
| return text; | ||||||||||
| } | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| export const simplifyUnicode = (text?: string) => | ||||||||||
| text | ||||||||||
| ? text | ||||||||||
|
|
@@ -165,9 +182,7 @@ export const romanizeHangul = (line: string) => | |||||||||
| esHangulRomanize(hanja.translate(line, 'SUBSTITUTION')); | ||||||||||
|
|
||||||||||
| export const romanizeChinese = (line: string) => { | ||||||||||
| return line.replaceAll(/[\u4E00-\u9FFF]+/g, (match) => | ||||||||||
| pinyin.convertToPinyin(match, ' ', true), | ||||||||||
| ); | ||||||||||
| return line.replaceAll(/[\u4E00-\u9FFF]+/g, (match) => pinyin(match)); | ||||||||||
|
||||||||||
| return line.replaceAll(/[\u4E00-\u9FFF]+/g, (match) => pinyin(match)); | |
| return line.replaceAll(/[\u4E00-\u9FFF]+/g, (match) => | |
| pinyin(match, { separator: ' ' }), | |
| ); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,10 @@ export type SyncedLyricsPluginConfig = { | |||||
| showLyricsEvenIfInexact: boolean; | ||||||
| lineEffect: LineEffect; | ||||||
| romanization: boolean; | ||||||
| convertChineseCharacter: | ||||||
|
||||||
| convertChineseCharacter: | |
| convertChineseCharacter?: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
.trim()call was removed when refactoring this line to support Chinese character conversion. This means text with leading or trailing whitespace will no longer be trimmed before display. Consider adding.trim()to the end of the text processing to maintain the original behavior.