longnow / icu-transliterator-service

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

icu-transliterator-service

This is a simple node.js web service to transliterate text via ICU rule-based transliterators. It requires the icu-transliterator module, for which you will need to install ICU components.

To start the server, install modules via npm install, then simply run:

$ node index.js

The server will listen on localhost port 3000 by default. You can override the default listen host address by setting the LISTENADDR environment variable, and the default port by setting the PORT environment variable.

To use the server, POST the text you wish to transliterate to a path containing the registered transliterator ID. The response will be the transliteration in plain text. For example:

$ curl http://localhost:3000/Latin-Cyrillic -d 'Dostoevskij'
Достоевский

The default transliteration direction is forward. You may add /forward or /reverse to the path to explicitly specify it:

$ curl http://localhost:3000/Latin-Cyrillic/reverse -d 'Достоевский'
Dostoevskij

The server will make available all rule-based transliterators provided with your version of ICU. You may also supply custom transliterators. To do so, create a file transliterators.json in the same directory as index.js, with the following format:

[
  {
    "name": "…",
    "rules": "…"
  },
  {
    "name": "…",
    "rules": "…"
  }
]

The server will read this file at startup and register a transliterator for each object in the array. It will register the transliterator as name, using the string in rules for the rules (see ICU docs for syntax). See transliterators-sample.json for an example containing a Balinese transliterator.

About

License:MIT License


Languages

Language:JavaScript 100.0%