Giter Club home page Giter Club logo

sanscript.js's Introduction

Sanscript.js

Introduction

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.

Usage

Sanscript is simple to use:

var output = Sanscript.t(input, from, to);

Here, from and to are the names of different schemes. In Sanscript, the word "scheme" refers to both scripts and romanizations. These schemes are of two types:

  1. Brahmic schemes, which are abugidas. All Indian scripts are Brahmic schemes.
  2. Roman schemes, which are alphabets. All romanizations are Roman schemes.

By default, Sanscript supports the following Brahmic schemes:

  • bengali
  • devanagari
  • gujarati
  • gurmukhi
  • kannada
  • malayalam
  • oriya
  • tamil
  • telugu

With a goal to later add the following Brahmic schemes:

  • `balinese'
  • `batak'
  • `brahmi'
  • `burmese'
  • `javanese'
  • `khmer'
  • `lao'
  • `lontara'
  • `sinhala'
  • `sudanese'
  • `thai'
  • `tibetan'

and the following Roman schemes:

  • hk (Harvard-Kyoto)
  • iast (International Alphabet of Sanskrit Transliteration)
  • itrans (ITRANS)
  • itrans_dravidian (ITRANS with support for Dravidian short "e" and "o")
  • kolkata (National Library at Kolkata)
  • slp1 (Sanskrit Library Phonetic Basic)
  • velthuis (Velthuis)
  • wx (WX)

Disabling transliteration

When Sanscript sees the token ##, it toggles the transliteration state:

Sanscript.t('ga##Na##pa##te', 'hk', 'devanagari'); // गNaपte
Sanscript.t('ध##र्म##क्षेत्रे', 'devanagari', 'hk'); // dhaर्मkSetre

When Sanscript sees the token \, it disables transliteration on the character that immediately follows. \ is used for ITRANS compatibility; we recommend always using ## instead.

Sanscript.t('a \\a', 'itrans', 'devanagari'); // अ a
Sanscript.t('\\##aham', 'itrans', 'devanagari'); // ##अहम्

Transliterating to lossy schemes

A lossy scheme does not have the letters needed to support lossless translation. For example, Bengali is a lossy scheme because it uses for both ba and va. In future releases, Sanscript might let you choose how to handle lossiness. For the time being, it makes some fairly bad hard-coded assumptions. Corrections and advice are always welcome.

Transliteration options

You can tweak the transliteration function by passing an options object:

var output = Sanscript.t(input, from, to, options);

options maps options to values. Currently, these options are supported:

  • skip_sgml - If true, transliterate SGML tags as if they were ordinary words (<b>iti</b><ब्>इति</ब्>). Defaults to false.
  • syncope - If true, use Hindi-style transliteration (ajayअजय). In linguistics, this behavior is known as schwa syncope. Defaults to false.

Adding new schemes

Adding a new scheme is simple:

Sanscript.addBrahmicScheme(schemeName, schemeData);
Sanscript.addRomanScheme(schemeName, schemeData);

For help in creating schemeData, see the comments on the addBrahmicScheme and addRomanScheme functions.

sanscript.js's People

Contributors

vg avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.