1.0.0 • Published 2 years ago
ytranslate v1.0.0
yTranslate
Getting started
First of all install the library:
npm install ytranslateThen import Translator:
import { Translator } from "ytranslate";Usage
After including package you can choose which engine you want to use (newest by default):
import { Engines, Translator } from "ytranslate";
Translator.setEngine(Engines.LEGACY);The Legacy engine is used if you are using the old API and have trns1.1... format keys. And then newest engine is used for new API version with XXXXXXXXXX-XXXXXXX-XXXXXX format keys.
Translation example
import { Translator } from "ytranslate";
const KEY = '<Your-seecret-key>';
const result = await Translator.translate('hello, world', { key: KEY, to: 'ru' });
console.log(result);All methods
translateThis method is designed to translate the specified text. Takes astringandtranslateSettingsas input.detectLanguageThis method is designed to determine the writing language for the specified text. Takes thestringandbaseSettingsas input.
baseSettings
keyThe value is of typestring. Obligatory field. Your secret key to access the API.
translateSettings
keyThe value is of typestring. Obligatory field. Your secret key to access the API.toThe value is of typestring. Obligatory field. Language to be translated into.fromThe value is of typestring. Optional field. Language to be translated from.glossaryConfig(ONLY IN NEWEST ENGINE) The value is of typeobject. Optional field. Glossary for use in translation. -glossaryDataThe value is of typeobject. Obligatory field. Pass the contents of the glossary in the request. -glossaryPairs[]The value is of typeobject. Obligatory field. Array of text pairs. The maximum total length of all source texts is 10,000 characters. The maximum total length of all translated texts is 10,000 characters. The number of elements must be in the range from 1 to 50. -sourceTextThe value is of typestring. Obligatory field. Text in original language. -translatedTextThe value is of typestring. Obligatory field. Text in target language.
1.0.0
2 years ago