Skip to content

Commit 430226a

Browse files
authored
Merge pull request #1 from Daksh777/copilot/port-hindi-bengali-romanization
Add Hindi & Bengali romanization support for synced lyrics
2 parents dffbfd2 + d8e2aae commit 430226a

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"dependencies": {
6666
"@dehoist/romanize-thai": "1.0.0",
6767
"@electron-toolkit/tsconfig": "1.0.1",
68+
"@indic-transliteration/sanscript": "1.3.3",
6869
"@electron/remote": "2.1.3",
6970
"@ffmpeg.wasm/core-mt": "0.12.0",
7071
"@ffmpeg.wasm/main": "0.12.0",

pnpm-lock.yaml

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/synced-lyrics/renderer/utils.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { romanize as esHangulRomanize } from 'es-hangul';
55
import hanja from 'hanja';
66
import * as pinyin from 'tiny-pinyin';
77
import { romanize as romanizeThaiFrag } from '@dehoist/romanize-thai';
8+
import Sanscript from '@indic-transliteration/sanscript';
89
import { lazy } from 'lazy-var';
910
import { detect } from 'tinyld';
1011

@@ -155,6 +156,14 @@ const hasChinese = (lines: string[]) =>
155156
const hasThai = (lines: string[]) =>
156157
lines.some((line) => /[\u0E00-\u0E7F]+/.test(line));
157158

159+
// https://en.wikipedia.org/wiki/Bengali_(Unicode_block)
160+
const hasBengali = (lines: string[]) =>
161+
lines.some((line) => /[\u0980-\u09FF]+/.test(line));
162+
163+
// https://en.wikipedia.org/wiki/Devanagari_(Unicode_block)
164+
const hasHindi = (lines: string[]) =>
165+
lines.some((line) => /[\u0900-\u097F]+/.test(line));
166+
158167
export const romanizeJapanese = async (line: string) =>
159168
(await kuroshiro.get()).convert(line, {
160169
to: 'romaji',
@@ -190,11 +199,25 @@ export const romanizeThai = (line: string) => {
190199
return latin;
191200
};
192201

202+
export const romanizeBengali = (line: string) => {
203+
return line.replaceAll(/[\u0980-\u09FF]+/g, (match) =>
204+
Sanscript.t(match, 'bengali', 'itrans'),
205+
);
206+
};
207+
208+
export const romanizeHindi = (line: string) => {
209+
return line.replaceAll(/[\u0900-\u097F]+/g, (match) =>
210+
Sanscript.t(match, 'devanagari', 'itrans'),
211+
);
212+
};
213+
193214
const handlers: Record<string, (line: string) => Promise<string> | string> = {
194215
ja: romanizeJapanese,
195216
ko: romanizeHangul,
196217
zh: romanizeChinese,
197218
th: romanizeThai,
219+
bn: romanizeBengali,
220+
hi: romanizeHindi,
198221
};
199222

200223
export const romanize = async (line: string) => {
@@ -210,6 +233,8 @@ export const romanize = async (line: string) => {
210233
if (hasKorean([line])) line = romanizeHangul(line);
211234
if (hasChinese([line])) line = romanizeChinese(line);
212235
if (hasThai([line])) line = romanizeThai(line);
236+
if (hasBengali([line])) line = romanizeBengali(line);
237+
if (hasHindi([line])) line = romanizeHindi(line);
213238

214239
return line;
215240
};

0 commit comments

Comments
 (0)