Git Product home page Git Product logo

translate-platforms's Introduction

Translate Platforms

A Node module to translate words by multiple platforms.

Installation

npm install translate-platforms

Usage

const { google, microsoft, youdao, baidu } = require('translate-platforms');
// async/await. The second parameter can be a language name (ISO 639-1)
const result = await google('Hello world', { to: google.ja });
console.log(result); 
// Output:
// {
//     lang: { from: 'en', to: 'ja' },
//     word: 'Hello world', 
//     text: 'こんにちは世界', 
//     candidate: [ 'こんにちは世界', 'こんにちは' ] 
// }
 
// Promises with .then(). The third parameter is the source language.
microsoft('こんにちは世界', { to: microsoft.zh }).then(result => {
  console.log(result);  
  // Output:
  // { 
  //     lang: { from: 'ja', to: 'zh' },
  //     word: 'こんにちは世界', 
  //     text: '你好世界', 
  //     candidate: [ ] 
  // }
});

Parameters

function translate(word: string, language: { from: string, to: string }): object
parameter description
word The word want to translate.
from The source language. Default is recognized automatically(auto). (Optional)
to The target language. Default is Chinese(zh). (Optional)

Return Object

key description
lang The source language and target language.
word The word want to translate.
text The most match result.
candidate Other translate result.

Language Code

Each platform supports different translation languages. You can check the interface function properties.

Support Platform

Supported platforms are Google, Microsoft, Yandex, Baidu, Tencent and Youdao.

Notice

Tencent does not support mutual translation of all languages, you can use the support function to get the translation language supported by the language.

translate-platforms's People

Contributors

imlinhanchao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

translate-platforms's Issues

Youdao's translation result text and word are reversed

youdao 的翻译结果 text 和 word 顺序颠倒了

  • translate-platforms v0.07
  • node v10
const { google, microsoft, youdao, baidu } = require('translate-platforms');
google('你好', { from: `zh`, to: `en` }).then(res => console.log(`google`, res));
microsoft('你好', { from: `zh`, to: `en` }).then(res => console.log(`microsoft`, res));
youdao('你好', { from: `zh`, to: `en` }).then(res => console.log(`youdao`, res));
baidu('你好', { from: `zh`, to: `en` }).then(res => console.log(`baidu`, res));

image

另外, 百度经常出错.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.