@@ -5,6 +5,7 @@ import { romanize as esHangulRomanize } from 'es-hangul';
55import hanja from 'hanja' ;
66import * as pinyin from 'tiny-pinyin' ;
77import { romanize as romanizeThaiFrag } from '@dehoist/romanize-thai' ;
8+ import Sanscript from '@indic-transliteration/sanscript' ;
89import { lazy } from 'lazy-var' ;
910import { detect } from 'tinyld' ;
1011
@@ -155,6 +156,14 @@ const hasChinese = (lines: string[]) =>
155156const 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+
158167export 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+
193214const 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
200223export 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