Getting Started with lilt.js

lilt.js adds interactive, adaptive machine translation to any HTML textarea. Translation memory matches can be optionally displayed.

The library consumes and can be used in conjunction with the Lilt REST API. For example, the REST API permits creation and training of custom memories.

For support, please visit and open the support chat window. There, you can also request an API key.


<script type="text/javascript" src=""></script>

The library is framework-independent and does not introduce any external dependencies (e.g., jQuery). But we do provide an adapter for Angular 1.x:

Angular 1.x

<script type="text/javascript" src=""></script>

Configure the library

The library consists of two parts: the service that handles all API requests and the translator that handles the translations:

<script type="text/javascript">
    Lilt.apikey = 'YOUR LILT API KEY';

    var service = Lilt.translationService('SOURCE_HASH', 'MEMORY_ID');
    var translator = Lilt.translator(service);


The standard workflow consists of the following steps:

  1. Create a memory
  2. Register a source segment
  3. Specify and configure an HTML <textarea> for translation.

Step 1: Create a MEMORY_ID for a language pair with the REST API:

$ curl -k --data "srclang=en&trglang=de&name=MyEnDeMemory"

Step 2: Get a SOURCE_HASH for a source string as follows:

$ curl -k

Step 3: Set the variables for the javascript library:

Lilt.apikey = 'MYAPIKEY';

var memoryId = MEMORY_ID;
var sourceHash = SOURCE_HASH;

var service = Lilt.translationService(sourceHash, memoryId);
var translator = Lilt.translator(service);

API Documentation

Library Interface

  • Lilt.apikey - Default API key
  • Lilt.version - Library version
  • Lilt.translationService(<SOURCE HASH>, <MEMORY ID>, <OPTIONS>) - Creates a new request handler for segment translations
  • Lilt.translator(<SERVICE>, <OPTIONS>) - Creates a new translator
  • Lilt.clearQueue() - Clear the queue of all pending requests


The service objects handles all API requests including queuing and caching.

var service = Lilt.translationService('dfxghf126K3%$)!5xwe2323sss', 434311, {
  n: 20,
  apiKey: 'OTHER KEY'


The translator parses the API and generates translation tokens (see below) for you.

var service = Lilt.translationService('dfxghf126K3%$)!5xwe2323sss', 434311);

var translator = Lilt.Translator(service, {
  noWhitespace: false // target language has no whitespaces (e.g. chinese)

translator.translate('Hello ', 6).then(function(translator) {

The translate method

The translator needs to be updated on every text or index (cursor position) change using the translate(<TEXT>, <INDEX>) function and returns a promise after update.

The usual workflow is to call translate after loading and at every onKeyup event on the input.


Attribute Type Example Description
promise object The promise of the last translate() call
text string "Hallo W" The current text of the editor
translation string "Hallo Welt!" The best translation as a full string
translationTokens array [{}, ...] The best translation as tokens
prefixTokens array [{}, ...] The tokens before the current word
availableTokens array [{}, ...] All tokens that that could come next in the translation
sourceText string "Hello World!" The source of the translation
sourceDiff string "Hi Welt" The source difference of the translation (see translation memories)
allTokens array [{}, ...] Plain unsorted array of all translation tokens
beforeText string "Hallo " The text before the index
index integer 6 Current index (e.g. cursor position) of the editor
isActive boolean [{}, ...] Active if the index is at the end of the current text
alternativeTokens array [{}, ...] Alternative suggestions for the current token
matchTokens array [{}, ...] Tokens that are beginning like the current word
suggestionMatchTokens array [{}, ...] Tokens that are beginning like the current word and are next in the translation
isExactMatch boolean Translation is a exact memory match
isSuggestionMatch boolean Target equals the translation
isExactSuggestionMatch boolean Target and translation are equalling the memory match
isPartialSuggestionMatch boolean Target and translation are partial equalling the memory match
isMemoryMatch boolean Translation is a exact or partial memory match
isMemorySuggestionMatch boolean Translation is a exact or partial memory match and target equals it
isPartialMatch boolean Translation is a partial memory match
score float 0.8 The quality score of the translation

Translation Tokens

A translation consists of multiple tokens that build the full translation.



"Hello John, nice to meet you."


    text: "Hello ",
    rawText: "Hello",
    delimiter: " ",
    trimmedText: "Hello,",
    hasDelimiter: true,
    isNonWord: false,
    isLast: false,
    hasText: true,
    text: "John, ",
    rawText: "John",
    delimiter: " ",
    trimmedText: "John,",
    punctuationSuffix: ",",


Attribute Type Example Description
text string "Hello, " Full text including delimiters and punctuation
rawText string "Hello" Text without delimiters and punctuation
delimiter string " " The delimiter of the token
trimmedText string "Hello," The text without delimiter
punctuationPrefix string "'" The prepended punctuation
punctuationSuffix string "." The appended punctuation
hasDelimiter boolean Token has an delimiter
isNonWord boolean Token dosen't contain any word characters (like "!!")
isLast boolean Last token in this translation
hasText boolean Token contains word characters
isBest boolean Is the from the best translation
isCurrent boolean Is the currently selected token
isMatch boolean Is partially or fully matching the current word
isExactMatch boolean Is fully matching the current word
isExactSuggestionMatch boolean Is fully matching and a next word suggestion
isSuggestion boolean Is a next word suggestion
isOtherMatch boolean Is not current but matching
isProvenance boolean Is a provenance
isPrefix boolean Is a prefix
isSuffix boolean Is a suffix
provenanceIndex integer Index of the provenance (if applicable)
Still need help? Get in touch!
Last updated on 12th May 2019