TranslatorEngine

TranslatorEngine

new TranslatorEngine(defaultValopt)

Description:
  • Handles how a text or an array of texts is translated from one language to another.
    Each translation app has its own protocol, api and method. This class takes care of that and at the same time hopes to make that diversity more uniform.

Source:
Parameters:
Name Type Attributes Description
defaultVal Object <optional>

Default value. Please provide an object with the TranslatorEngine like structure.

Members

author

Description:
  • Author of this engine

Source:
Default Value:
  • Anonymous

Author of this engine

batchDelay

Description:
  • Batch delay.
    The waiting time between batch. Some server will ban user if you send intense attack like requests.

Source:
Default Value:
  • 5000

Batch delay.
The waiting time between batch. Some server will ban user if you send intense attack like requests.

delimiter

Description:
  • delimiter for each line. Pick character that will be obeyed by translator engine.
    The possition of the delimiter for the resulted translation should be intact and unchanged.
    if the number of lines of original text doesn't match with translation result...dissaster will be occured!

    Example:
    Google treat line break as line separator. You should use \n (or \r\n) for google.

Source:
Default Value:
  • \n

delimiter for each line. Pick character that will be obeyed by translator engine.
The possition of the delimiter for the resulted translation should be intact and unchanged.
if the number of lines of original text doesn't match with translation result...dissaster will be occured!

Example:
Google treat line break as line separator. You should use \n (or \r\n) for google.

description

Description:
  • Description of the engine.

Source:

Description of the engine.

escapeAlgorithm

Description:
  • Escape algorithm to escape subset of string.

Source:

Escape algorithm to escape subset of string.

id

Description:
  • ID of the engine. Must be unique.

Source:

ID of the engine. Must be unique.

languages

Description:
  • Supported languages of the translator
    default is whatever google supports

Source:

Supported languages of the translator
default is whatever google supports

maxRequestLength

Description:
  • Maximum request length for each batch in characters.

Source:
Default Value:
  • 5000

Maximum request length for each batch in characters.

name

Description:
  • Display name of the engine

Source:

Display name of the engine

optionsForm :Object

Description:
Source:

A JSON Form object to generate a form for options.
More about JSON Form:
https://github.com/jsonform/jsonform/wiki

Type:
  • Object

version

Description:
  • Engine version

Source:

Engine version

Methods

getLanguageCode(standardCode, langTableopt) → {String}

Description:
  • Convert language code from the unified language code to this engine's language code.

Source:
Since:
  • 4.10.1
Example
trans.getTranslatorEngine("lingvaNex").getLanguageCode("ja")
// ja_JP
Parameters:
Name Type Attributes Description
standardCode String

Standard language code

langTable String <optional>

Language table. sl||tl

Returns:
  • This engine's language code
Type
String

getOptions(key) → {*}

Description:
  • Get option from this translator engine.

Source:
Parameters:
Name Type Description
key *

Key of the object

Returns:

Value of the retreived data

Type
*

translate(text, optionsopt, optionsopt) → {Promise.<TranslationResult>}

Description:
  • Method to translate text(s)
    This function is to be replaced with a handler for each translator end point/apps.

Source:
Examples

Translation with `await` call

var result = await trans.getTranslatorEngine("deepl").translate(["こんにちは"])
console.log(result.translation);
// prints an array: ["Hello. - Hello."]

Use array to perform batch translation

var result = await trans.getTranslatorEngine("sugoitrans").translate(["こんにちは", "こんばんは。"], {sl:"ja", tl:"en"})
Parameters:
Name Type Attributes Default Description
text String | Array.<String>

Text(s) to translate

options Object <optional>
{}

Options

Properties
Name Type Attributes Default Description
sl String <optional>
trans.getSl()

Source language.

tl String <optional>
trans.getTl()

Target language.

onAfterLoading function <optional>

Callback after process is success.

onError function <optional>

Callback when process is error.

always function <optional>

Callback after process is completed.

options Object <optional>

Options

Returns:
Type
Promise.<TranslationResult>

update(key, value)

Description:
  • Update a configuration and store it to the system.
    The value will be saved and remembered when the system is saved.

Source:
Parameters:
Name Type Description
key String

Key of the key-value pair

value *

Value of the key-value pair