Translate Node Module
A node module to translate. There is power by Google Translate.
Installation
npm install translator-promise
Usage
const translate = require('translator-promise');
const result = await translate('Hello world', 'ja');
console.log(result);
translate('こんにちは世界', 'cn', 'ja').then(result => {
console.log(result);
});
Parameters
function translate(word: string, to: string, from: string): object
parameter | description |
---|
word | The word want to translate. |
to | The target language. Default is Chinese(cn ). (Optional) |
from | The source language. Default is recognized automatically(auto ). (Optional) |
Note: If there is no source language, the language will be recognized automatically. When there is about 33.3% Chinese, the source language will be changed to Chinese.
Return Object
key | description |
---|
word | The word want to translate. |
text | The most match result. |
candidate | Other translate result. |
Language Code
You can check it in here (ISO 639-1).
Example
translate('word', 'ja');
translate('中文', 'ko', 'zh');
translate('中文');
translate('用 Google 翻译一下这条句子。');