marathi-transliterate 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/package.json +1 -1
- package/src/dictionary.js +173 -0
- package/src/index.js +59 -10
package/README.md
CHANGED
|
@@ -146,6 +146,29 @@ Converts full text, sentences, or paragraphs into Marathi while preserving numbe
|
|
|
146
146
|
### `getSuggestions(word: string): string[]`
|
|
147
147
|
Returns candidate phonetic variations for a given word.
|
|
148
148
|
|
|
149
|
+
### `extendDictionary(customWords: Record<string, string>): void`
|
|
150
|
+
Extends or overrides the global transliteration dictionary with your own custom vocabulary at runtime.
|
|
151
|
+
|
|
152
|
+
```javascript
|
|
153
|
+
import { extendDictionary, transliterateWord } from "marathi-transliterate";
|
|
154
|
+
|
|
155
|
+
extendDictionary({
|
|
156
|
+
"sangamner": "संगमनेर",
|
|
157
|
+
"myitem": "माझामाल"
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
transliterateWord("sangamner"); // → "संगमनेर"
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### `normalizeMarathi(text: string): string`
|
|
164
|
+
Normalizes Marathi characters (interchangeable ळ/ल, श/ष, ि/ी, ु/ू, and anusvara) for tolerant comparisons and search filtering.
|
|
165
|
+
|
|
166
|
+
```javascript
|
|
167
|
+
import { normalizeMarathi } from "marathi-transliterate";
|
|
168
|
+
|
|
169
|
+
normalizeMarathi("भुसाळ") === normalizeMarathi("भुसाल"); // → true
|
|
170
|
+
```
|
|
171
|
+
|
|
149
172
|
### `attachDevanagari(element, options): Handler`
|
|
150
173
|
Attaches keyboard listeners to an `<input>` or `<textarea>` element.
|
|
151
174
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "marathi-transliterate",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Zero-dependency, offline-first Marathi / Devanagari phonetic transliteration library. Converts English typing to Marathi (e.g. sakhar -> साखर) seamlessly in plain JS, Node.js, and frontend frameworks.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
package/src/dictionary.js
CHANGED
|
@@ -380,5 +380,178 @@ export const MARATHI_DICTIONARY = {
|
|
|
380
380
|
'te': 'ते',
|
|
381
381
|
'ha': 'हा',
|
|
382
382
|
'hi': 'ही'
|
|
383
|
+
,
|
|
384
|
+
|
|
385
|
+
// --- Extended Surnames, Names & Kirana Vocabulary ---
|
|
386
|
+
'badama': 'बदाम',
|
|
387
|
+
'pistachio': 'पिस्ता',
|
|
388
|
+
'raisins': 'मनुका',
|
|
389
|
+
'akrod': 'अक्रोड',
|
|
390
|
+
'dal': 'डाळ',
|
|
391
|
+
'daal': 'डाळ',
|
|
392
|
+
'bhel': 'भेळ',
|
|
393
|
+
'keli': 'केळी',
|
|
394
|
+
'kele': 'केळी',
|
|
395
|
+
'haladi': 'हळद',
|
|
396
|
+
'shevaya': 'शेवया',
|
|
397
|
+
'naral': 'नारळ',
|
|
398
|
+
'nariyal': 'नारळ',
|
|
399
|
+
'khul': 'खूळ',
|
|
400
|
+
'khula': 'खुळा',
|
|
401
|
+
'khuli': 'खुळी',
|
|
402
|
+
'goli': 'गोळी',
|
|
403
|
+
'golya': 'गोळ्या',
|
|
404
|
+
'dole': 'डोळे',
|
|
405
|
+
'dola': 'डोळा',
|
|
406
|
+
'khel': 'खेळ',
|
|
407
|
+
'vel': 'वेळ',
|
|
408
|
+
'chul': 'चूल',
|
|
409
|
+
'pola': 'पोळा',
|
|
410
|
+
'shengdana': 'शेंगदाणा',
|
|
411
|
+
'shengdaane': 'शेंगदाणे',
|
|
412
|
+
'dana': 'दाणा',
|
|
413
|
+
'peanut': 'शेंगदाणे',
|
|
414
|
+
'groundnut': 'शेंगदाणे',
|
|
415
|
+
'cumin': 'जिरे',
|
|
416
|
+
'chilli': 'मिरची',
|
|
417
|
+
'matar': 'मटार',
|
|
418
|
+
'khule': 'खुळे',
|
|
419
|
+
'khulee': 'खुळे',
|
|
420
|
+
'khulay': 'खुळे',
|
|
421
|
+
'mule': 'मुळे',
|
|
422
|
+
'muley': 'मुळे',
|
|
423
|
+
'moole': 'मुळे',
|
|
424
|
+
'kamble': 'कांबळे',
|
|
425
|
+
'kambale': 'कांबळे',
|
|
426
|
+
'kamle': 'कांबळे',
|
|
427
|
+
'dhole': 'ढोळे',
|
|
428
|
+
'dholay': 'ढोळे',
|
|
429
|
+
'gole': 'गोळे',
|
|
430
|
+
'golay': 'गोळे',
|
|
431
|
+
'shelke': 'शेळके',
|
|
432
|
+
'shelake': 'शेळके',
|
|
433
|
+
'walunj': 'वाळुंज',
|
|
434
|
+
'walunje': 'वाळुंजे',
|
|
435
|
+
'valunj': 'वाळुंज',
|
|
436
|
+
'valunje': 'वाळुंजे',
|
|
437
|
+
'ingale': 'इंगळे',
|
|
438
|
+
'ingle': 'इंगळे',
|
|
439
|
+
'ingole': 'इंगोले',
|
|
440
|
+
'salve': 'साळवे',
|
|
441
|
+
'saalve': 'साळवे',
|
|
442
|
+
'salunke': 'साळुंखे',
|
|
443
|
+
'jawale': 'जावळे',
|
|
444
|
+
'zavale': 'जावळे',
|
|
445
|
+
'bawale': 'बावळे',
|
|
446
|
+
'bavale': 'बावळे',
|
|
447
|
+
'phalke': 'फाळके',
|
|
448
|
+
'falke': 'फाळके',
|
|
449
|
+
'chalke': 'चाळके',
|
|
450
|
+
'pimple': 'पिंपळे',
|
|
451
|
+
'pimpal': 'पिंपळे',
|
|
452
|
+
'tambole': 'तांबोळे',
|
|
453
|
+
'mahale': 'महाळे',
|
|
454
|
+
'bhale': 'भाळे',
|
|
455
|
+
'bhalerao': 'भालेराव',
|
|
456
|
+
'borule': 'बोरुळे',
|
|
457
|
+
'gholap': 'घोळप',
|
|
458
|
+
'pol': 'पोळ',
|
|
459
|
+
'bal': 'बाळ',
|
|
460
|
+
'baal': 'बाळ',
|
|
461
|
+
'dalvi': 'दळवी',
|
|
462
|
+
'dalavi': 'दळवी',
|
|
463
|
+
'palve': 'पाळवे',
|
|
464
|
+
'palande': 'पाळंदे',
|
|
465
|
+
'zole': 'झोळे',
|
|
466
|
+
'jole': 'जोळे',
|
|
467
|
+
'wable': 'वाबळे',
|
|
468
|
+
'wabale': 'वाबळे',
|
|
469
|
+
'bhole': 'भोळे',
|
|
470
|
+
'ghule': 'घुळे',
|
|
471
|
+
'dhule': 'धुळे',
|
|
472
|
+
'khole': 'खोळे',
|
|
473
|
+
'thole': 'ठोळे',
|
|
474
|
+
'chitale': 'चितळे',
|
|
475
|
+
'chitapale': 'चितपळे',
|
|
476
|
+
'daphal': 'डफळ',
|
|
477
|
+
'raul': 'राऊळ',
|
|
478
|
+
'rawool': 'राऊळ',
|
|
479
|
+
'ravul': 'राऊळ',
|
|
480
|
+
'kolhe': 'कोल्हे',
|
|
481
|
+
'kolhewadi': 'कोल्हेवाडी',
|
|
482
|
+
'sawale': 'सावळे',
|
|
483
|
+
'kawale': 'कावळे',
|
|
484
|
+
'gavale': 'गवळे',
|
|
485
|
+
'gawale': 'गवळे',
|
|
486
|
+
'navale': 'नवळे',
|
|
487
|
+
'nawale': 'नवळे',
|
|
488
|
+
'dewale': 'देवळे',
|
|
489
|
+
'yewale': 'येवळे',
|
|
490
|
+
'yeole': 'येवले',
|
|
491
|
+
'dahale': 'डहाळे',
|
|
492
|
+
'bhabale': 'भाबळे',
|
|
493
|
+
'tapale': 'तापळे',
|
|
494
|
+
'kulat': 'कुळट',
|
|
495
|
+
'landge': 'लांडगे',
|
|
496
|
+
'kaale': 'काळे',
|
|
497
|
+
'maali': 'माळी',
|
|
498
|
+
'bhosle': 'भोसले',
|
|
499
|
+
'shirke': 'शिर्के',
|
|
500
|
+
'shewale': 'शेवाळे',
|
|
501
|
+
'shiwale': 'शिवाळे',
|
|
502
|
+
'bhilare': 'भिळारे',
|
|
503
|
+
'padwal': 'पडवळ',
|
|
504
|
+
'bhadwalkar': 'भाडवळकर',
|
|
505
|
+
'bendale': 'बेंदळे',
|
|
506
|
+
'ghodke': 'घोडके',
|
|
507
|
+
'khadke': 'खडके',
|
|
508
|
+
'phadke': 'फडके',
|
|
509
|
+
'kakade': 'काकडे',
|
|
510
|
+
'pawale': 'पावळे',
|
|
511
|
+
'sonawale': 'सोनावळे',
|
|
512
|
+
'sonawane': 'सोनवणे',
|
|
513
|
+
'borhade': 'बोऱ्हाडे',
|
|
514
|
+
'katore': 'कटोरे',
|
|
515
|
+
'shete': 'शेटे',
|
|
516
|
+
'bhusal': 'भुसाळ',
|
|
517
|
+
'bhusaal': 'भुसाळ',
|
|
518
|
+
'bhusale': 'भुसाळे',
|
|
519
|
+
'bhuswal': 'भुसावळ',
|
|
520
|
+
'bhusawal': 'भुसावळ',
|
|
521
|
+
'ghusal': 'घुसाळ',
|
|
522
|
+
'kusal': 'कुसळ',
|
|
523
|
+
'sable': 'साबळे',
|
|
524
|
+
'sabale': 'साबळे',
|
|
525
|
+
'taral': 'तराळ',
|
|
526
|
+
'taraal': 'ताराळ',
|
|
527
|
+
'pusal': 'पुसळ',
|
|
528
|
+
'chitole': 'चितोळे',
|
|
529
|
+
'shitole': 'शितोळे',
|
|
530
|
+
'bapule': 'बापुळे',
|
|
531
|
+
'kharpude': 'खरपुडे',
|
|
532
|
+
'wadkar': 'वाडकर',
|
|
533
|
+
'kote': 'कोते',
|
|
534
|
+
'balu': 'बाळू',
|
|
535
|
+
'baalu': 'बाळू',
|
|
536
|
+
'bala': 'बाळा',
|
|
537
|
+
'balasaheb': 'बाळासाहेब',
|
|
538
|
+
'balaji': 'बाळाजी',
|
|
539
|
+
'baliram': 'बळीराम',
|
|
540
|
+
'kalyani': 'कल्याणी',
|
|
541
|
+
'sheela': 'शीला',
|
|
542
|
+
'sheetal': 'शीतल',
|
|
543
|
+
'snehal': 'स्नेहल',
|
|
544
|
+
'pranjal': 'प्रांजल',
|
|
545
|
+
'atul': 'अतुल',
|
|
546
|
+
'komal': 'कोमल',
|
|
547
|
+
'mangal': 'मंगल',
|
|
548
|
+
'ujwala': 'उज्ज्वला',
|
|
549
|
+
'ujjwala': 'उज्ज्वला',
|
|
550
|
+
'payal': 'पायल',
|
|
551
|
+
'kajal': 'काजल',
|
|
552
|
+
'sejal': 'सेजल',
|
|
553
|
+
'nilesh': 'निलेश',
|
|
554
|
+
'shailesh': 'शैलेश',
|
|
555
|
+
'kamlesh': 'कमलेश'
|
|
383
556
|
};
|
|
384
557
|
|
package/src/index.js
CHANGED
|
@@ -4,18 +4,48 @@
|
|
|
4
4
|
* for Marathi (Devanagari) script with live smart suggestions.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { MARATHI_DICTIONARY } from
|
|
8
|
-
import { phoneticTransliterateWord } from
|
|
9
|
-
import { getCachedWord, setCachedWord, fetchOnlineMarathi } from
|
|
10
|
-
import { attachDevanagari } from
|
|
7
|
+
import { MARATHI_DICTIONARY } from "./dictionary.js";
|
|
8
|
+
import { phoneticTransliterateWord } from "./phonetics.js";
|
|
9
|
+
import { getCachedWord, setCachedWord, fetchOnlineMarathi } from "./cache.js";
|
|
10
|
+
import { attachDevanagari } from "./dom.js";
|
|
11
11
|
|
|
12
12
|
export { MARATHI_DICTIONARY, fetchOnlineMarathi, attachDevanagari };
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Extends or overrides the global transliteration dictionary at runtime.
|
|
16
|
+
* @param {Record<string, string>} customWords - Map of English -> Marathi words
|
|
17
|
+
*/
|
|
18
|
+
export function extendDictionary(customWords) {
|
|
19
|
+
if (customWords && typeof customWords === "object") {
|
|
20
|
+
Object.assign(MARATHI_DICTIONARY, customWords);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Normalizes Marathi characters (interchangeable ळ/ल, श/ष, ि/ी, ु/ू, and anusvar)
|
|
26
|
+
* for tolerant comparisons and search filtering.
|
|
27
|
+
* @param {string} str
|
|
28
|
+
* @returns {string}
|
|
29
|
+
*/
|
|
30
|
+
export function normalizeMarathi(str) {
|
|
31
|
+
if (!str) return "";
|
|
32
|
+
return String(str)
|
|
33
|
+
.toLowerCase()
|
|
34
|
+
.replace(/ळ/g, "ल")
|
|
35
|
+
.replace(/ष/g, "श")
|
|
36
|
+
.replace(/ी/g, "ि")
|
|
37
|
+
.replace(/ू/g, "ु")
|
|
38
|
+
.replace(/[ँं]/g, "")
|
|
39
|
+
.trim();
|
|
40
|
+
}
|
|
41
|
+
|
|
14
42
|
/**
|
|
15
43
|
* Transliterates a single English word into Marathi (Devanagari).
|
|
16
|
-
* @param {string} word - Romanized word e.g. sakhar, kanda,
|
|
44
|
+
* @param {string} word - Romanized word e.g. sakhar, kanda, batata
|
|
45
|
+
* @returns {string} - Marathi Devanagari script e.g. साखर, कांदा, बटाटा
|
|
46
|
+
*/
|
|
17
47
|
export function transliterateWord(word) {
|
|
18
|
-
if (!word) return
|
|
48
|
+
if (!word) return "";
|
|
19
49
|
const clean = word.toLowerCase().trim();
|
|
20
50
|
|
|
21
51
|
// 1. Check curated high-accuracy dictionary first
|
|
@@ -33,7 +63,7 @@ export function transliterateWord(word) {
|
|
|
33
63
|
const phonetic = phoneticTransliterateWord(word);
|
|
34
64
|
|
|
35
65
|
// Background fetch to enrich cache if online (non-blocking)
|
|
36
|
-
if (typeof fetch !==
|
|
66
|
+
if (typeof fetch !== "undefined") {
|
|
37
67
|
fetchOnlineMarathi(clean).catch(() => {});
|
|
38
68
|
}
|
|
39
69
|
|
|
@@ -47,7 +77,7 @@ export function transliterateWord(word) {
|
|
|
47
77
|
* @returns {string} - Transliterated text
|
|
48
78
|
*/
|
|
49
79
|
export function transliterate(text) {
|
|
50
|
-
if (!text) return
|
|
80
|
+
if (!text) return "";
|
|
51
81
|
|
|
52
82
|
return text.replace(/[a-zA-Z]+/g, match => {
|
|
53
83
|
return transliterateWord(match);
|
|
@@ -61,6 +91,9 @@ export const toDevanagari = transliterate;
|
|
|
61
91
|
|
|
62
92
|
/**
|
|
63
93
|
* Returns ranked candidate spelling suggestions for a word.
|
|
94
|
+
* Guarantees that any word containing "l" automatically provides both "ळ" (LLA)
|
|
95
|
+
* and "ल" (LA) variants in candidate suggestions (e.g. bhusal -> भुसाळ, भुसळ, भुसल).
|
|
96
|
+
*
|
|
64
97
|
* @param {string} word
|
|
65
98
|
* @param {Object} [options]
|
|
66
99
|
* @param {number} [options.maxSuggestions=5]
|
|
@@ -95,7 +128,21 @@ export function getSuggestions(word, options = {}) {
|
|
|
95
128
|
const phonetic = phoneticTransliterateWord(word);
|
|
96
129
|
if (phonetic) add(phonetic);
|
|
97
130
|
|
|
98
|
-
// 4.
|
|
131
|
+
// 4. Smart Marathi ळ (LLA) and ल (LA) variants expansion
|
|
132
|
+
const initialCandidates = [...suggestions];
|
|
133
|
+
for (const s of initialCandidates) {
|
|
134
|
+
if (s.includes("ल")) {
|
|
135
|
+
// Special Marathi phonetic rule: words ending in "al" often end in "ाळ" (e.g. bhusal -> भुसाळ)
|
|
136
|
+
if (clean.endsWith("al") && s.endsWith("ल")) {
|
|
137
|
+
add(s.slice(0, -1) + "ाळ");
|
|
138
|
+
}
|
|
139
|
+
add(s.replace(/ल/g, "ळ"));
|
|
140
|
+
} else if (s.includes("ळ")) {
|
|
141
|
+
add(s.replace(/ळ/g, "ल"));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// 5. Prefix matches from dictionary (if clean.length >= 3)
|
|
99
146
|
if (clean.length >= 3 && suggestions.length < max) {
|
|
100
147
|
for (const [key, val] of Object.entries(MARATHI_DICTIONARY)) {
|
|
101
148
|
if (key.startsWith(clean) && key !== clean) {
|
|
@@ -105,7 +152,7 @@ export function getSuggestions(word, options = {}) {
|
|
|
105
152
|
}
|
|
106
153
|
}
|
|
107
154
|
|
|
108
|
-
//
|
|
155
|
+
// 6. Add raw English word at the end so user can easily keep original
|
|
109
156
|
if (includeOriginal && !suggestions.includes(word)) {
|
|
110
157
|
suggestions.push(word);
|
|
111
158
|
}
|
|
@@ -120,6 +167,8 @@ export default {
|
|
|
120
167
|
toDevanagari,
|
|
121
168
|
getSuggestions,
|
|
122
169
|
attachDevanagari,
|
|
170
|
+
extendDictionary,
|
|
171
|
+
normalizeMarathi,
|
|
123
172
|
MARATHI_DICTIONARY,
|
|
124
173
|
fetchOnlineMarathi
|
|
125
174
|
};
|