Skip to content

Commit

Permalink
Wordwise transliteration
Browse files Browse the repository at this point in the history
  • Loading branch information
vvasuki committed Feb 12, 2024
1 parent 6b6e1b3 commit 261946b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
20 changes: 12 additions & 8 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@indic-transliteration/sanscript",
"version": "1.3.0",
"version": "1.3.1",
"description": "Sanscript is a transliteration library for Indian languages. It supports the most popular Indian scripts and several different romanization schemes. Although Sanscript focuses on Sanskrit transliteration, it has partial support for other languages and is easy to extend.",
"main": "sanscript.js",
"types": "./types/sanscript.d.ts",
Expand Down
18 changes: 18 additions & 0 deletions src/sanscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,24 @@ function exportSanscriptSingleton (global, schemes, devanagariVowelToMarks) {
return result;
};

/**
* A function to transliterate each word, for the benefit of script learners.
*
* @param data
* @param from
* @param to
* @param options
*/
Sanscript.transliterateWordwise = function (data, from, to, options) {
options = options || {};
const words = data.split(/\s+/);
const word_tuples = words.map(function (word) {
const result = Sanscript.t(word, from, to, options);
return [word, result];
});
return word_tuples;
};

// Now that Sanscript is fully defined, we now safely export it for use elsewhere.
// The below block was copied from https://www.npmjs.com/package/sanscript .
// define seems to be a requirejs thing https://requirejs.org/docs/whyamd.html#amd .
Expand Down
4 changes: 4 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,3 +640,7 @@ QUnit.test("Non-Sanskrit letters", function () {
// const dev_iso = transHelper("devanagari", "iso");
// dev_iso("फ़ोन सड़क ज़्यादा", "fōna saṛaka zyaada");
});

QUnit.test("Transliterate wordwise", function () {
QUnit.assert.equal(Sanscript.transliterateWordwise("रामो दाशरथिर् यदि", "devanagari", "iso").toString(), [["रामो", "rāmō"], ["दाशरथिर्", "dāśarathir"], ["यदि", "yadi"]].toString(), "wordwise");
});

0 comments on commit 261946b

Please sign in to comment.