• Stars
    star
    217
  • Rank 178,380 (Top 4 %)
  • Language
    TypeScript
  • License
    Apache License 2.0
  • Created almost 5 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A free and unlimited API for Google Translate(support single text and Multi-segment text) 💵🚫

google-translate-open-api

A free and unlimited API for Google Translate(support single text and Multi-segment text) 💵🚫

Support me

中文| English

Feature

  • Multi-segment text support
  • Auto language detection
  • Spelling correction
  • Language correction
  • Fast and reliable – it uses the same servers that translate.google.com uses
  • Free and unlimited (translate.google.com uses a token to authorize the requests. If you are not Google, you do not have this token and will have to pay $20 per 1 million characters of text)

Install

npm install --save google-translate-open-api

Why this repo ?

when I have the following sentence. ( from How Are Function Components Different from Classes?)

Maybe you’ve heard one of them is better for performance. Which one? Many of such benchmarks are flawed so I’d be careful drawing conclusions from them.

I don't want to translate all the text first and I'd like to translate segment by segment. Especially in an article, the whole translation may not work well.

1565448193440.jpg

1565516309452.jpg

In the existing library, if I want to translate multi-segment text, I have to request multiple times.(like google-translate-api)

So I have to use the new api to implement, so the google-translate-open-api is born.

Usage

Single segment

import translate from 'google-translate-open-api';
const result = await translate(`I'm fine.`, {
  tld: "cn",
  to: "zh-CN",
});
const data = result.data[0];

// 我很好。

Multi-segment text

import translate from 'google-translate-open-api';

const result = await translate([`I'm fine.`, `I'm ok.`], {
  tld: "cn",
  to: "zh-CN",
});
const data = result.data[0];
// [[[["我很好。"]],null,"en"],[[["我可以。"]],null,"en"]]

Note: Multi-segment text result is different from single sentence. You need extra attention.

Multi-segment text contains mylti-sentence.

import translate, { parseMultiple } from 'google-translate-open-api';

const result = await translate([`I'm fine. And you?`,`I'm ok.`], {
  tld: "cn",
  to: "zh-CN",
});
// [[[[["<i>I&#39;m fine.</i> <b>我很好。</b> <i>And you?</i> <b>你呢?</b>"]],null,"en"],[[["我可以。"]],null,"en"]]]

// use parseMultiple
const data = result.data[0];
const parseData = parseMultiple(data);
// ["我很好。你呢?","我可以。"]

Proxy

proxy-config https://github.com/axios/axios#request-config

const result = await translate([`I'm fine. And you?`,`I'm ok.`], {
  tld: "cn",
  to: "zh-CN",
  proxy: {
    host: '127.0.0.1',
    port: 9000,
    auth: {
      username: 'mikeymike',
      password: 'rapunz3l'
    }
  }
});

Browers

const result = await translate([`I'm fine. And you?`,`I'm ok.`], {
  tld: "cn",
  to: "zh-CN",
  browers: true
});

const data = result.data[0];

// 我很好。

For commonJS

const translate = require('google-translate-open-api').default;

Multi-Terminal Example

https://github.com/hua1995116/google-translate-open-api-demo

API

translate(text, options)

text

Type: string

The text to be translated

options

Type: object

from? Type: string Default: auto

The text language. Must be auto or one of the codes/names (not case sensitive) contained in src/languages.ts

to Type: string Default: en

The language in which the text should be translated. Must be one of the codes/names (not case sensitive) contained in src/languages.ts.

tld Type: string 'com' | 'cn' <Default 'com'>

cn is for China, com for others.

proxy Type: AxiosProxyConfig

proxy for request.

config Type: object

config for axios

browers Type: boolean

support browers via cors-anywhere (This is a public service, not necessarily stable)

browersUrl Type: string

custom browers proxy url

format Type: string <text|html>

When use single translate, default use text (but we can set it to html) and use batch translate, default and only use html.

Related

Inspiration

License

Apache License

Copyright (c) 2019 蓝色的秋风

More Repositories

1

awesome-ai-painting

AI绘画资料合集(包含国内外可使用平台、使用教程、参数教程、部署教程、业界新闻等等) stable diffusion tutorial、disco diffusion tutorial、 AI Platform
9,971
star
2

webchat

🔈 Websocket project based on vue(基于vue2.0的实时聊天项目)
JavaScript
1,951
star
3

react-resume-site

木及简历,一款markdown的在线简历工具。 https://www.mujicv.com
TypeScript
1,798
star
4

musiccloudWebapp

🎧vuejs仿网易云音乐
Vue
727
star
5

360-sneakers-viewer

鸿星尔克全景(360°)鞋子展示(包含建模过程)
HTML
275
star
6

node-demo

所有实战项目示例
HTML
217
star
7

react-shopping

👞基于react的购物车实战项目
JavaScript
171
star
8

linec

🍬一个高颜值命令行统计代码行数的计数器。(counts lines of code)
JavaScript
120
star
9

mmt

A tool that automatically opens multiple panes to execute multiple commands in MacOS + iTerm2
TypeScript
62
star
10

git-down-repo

:octocat:Download git-repo for any url
JavaScript
54
star
11

shark-cleaner

A cleaning tool to help you quickly clear cache garbage.
JavaScript
50
star
12

Fly-Three.js

Three.js 起飞系列
JavaScript
47
star
13

mcharts

📝一个前端监控系统。
JavaScript
45
star
14

easy-json-parse

Parse your json safely and easily.
TypeScript
32
star
15

shaoshupai-trending-hot-search

少数派热门榜,记录从 2022-01-09 日开始的少数派热门文章。每天 21:00 抓取,按天归档。
JavaScript
21
star
16

npm-stat

download statistics for npm/cnpm packages
TypeScript
20
star
17

vuepress-blog

JavaScript
18
star
18

proxy

http-porxy 源码解析以及实现
JavaScript
16
star
19

myblog

a blog for hua1995116.
HTML
12
star
20

node-crawler

基于nodejs的爬虫
JavaScript
12
star
21

awesome-WebVR

Resources of WebVR(includes demo、framework and articles ) 关于 webVR 相关资源、咨询、工具、框架、平台。
8
star
22

vue

vue学习项目例子
JavaScript
8
star
23

shuhui

PHP基于web的书法设计作品网站
JavaScript
7
star
24

LRU-node-addon

A native module for Node supporting LRU (least-recently-used).
C++
7
star
25

tiny-webpack

A tiny webpack.
TypeScript
6
star
26

hua1995116

4
star
27

debug

debug demo
JavaScript
4
star
28

translate-md-viewer

This is a chrome extension to solve problem that people look at English article hardly.
JavaScript
3
star
29

timing-browser

前端监控-浏览器端
JavaScript
3
star
30

package-io

🛠package.json io
TypeScript
3
star
31

packaging-example

JavaScript
3
star
32

dark-mode

example for dark mode with vue3 and vite
Vue
2
star
33

Havetrip

JavaScript
2
star
34

apicloud-aistudy

a new project
HTML
2
star
35

cv-design

Vue
2
star
36

websocket-ws

a websocket sdk
JavaScript
2
star
37

vscode-daily-line

Calculate your daily programming time and number of lines
TypeScript
2
star
38

mmt-site

mmt site
TypeScript
2
star
39

webpack-plugin-inner-script

a plugin for webpack
JavaScript
2
star
40

GPTsEasy

Fint GTPs Easy
2
star
41

renting-tool

a tool for renting
JavaScript
1
star
42

node-tools

node-tools
JavaScript
1
star
43

fengchao

24号
CSS
1
star
44

shadow

JavaScript
1
star
45

sass-benchmark

Benchmark for Dart Sass sync/async and Node Sass
SCSS
1
star
46

svelte-ts-tailwind-vite-template

a template for svelte + ts + tailwind + vite.
Svelte
1
star
47

github-space

EJS
1
star
48

Casper-theme

ghost theme
CSS
1
star
49

newyear2018

new year for 2018
JavaScript
1
star
50

jwt

a simple instance for jwt.
TypeScript
1
star
51

Zero

Mobile UI for Vue.js
1
star
52

ip-search

a service for search ip
Go
1
star
53

bifrost

bifrost
JavaScript
1
star
54

bamboo

JavaScript
1
star
55

UploadLoading

UploadLoading
HTML
1
star
56

qushequ

qushequ
Java
1
star
57

auto-eating

1
star
58

2019-nCoV

CSS
1
star
59

eleme-vuejs

vuejs-1.0
Vue
1
star
60

leetcode

practice for arithmetic
HTML
1
star
61

common-comment-parser

A universal comment parser (supports more than 30 languages)
TypeScript
1
star
62

timing-receive

前端监控接受端
JavaScript
1
star
63

react-system

一个前端发布系统
JavaScript
1
star
64

react-system-node

The end of react-system
JavaScript
1
star
65

rsa

rsa
JavaScript
1
star
66

demo-publish-02

demo2 for publish
JavaScript
1
star
67

vue-flex-touch

A Vue.js directive both for long press touch on mobile and right click on pc.
Vue
1
star
68

awesome-comfyui

1
star
69

vue-online-editor

JavaScript
1
star
70

plus-in

JavaScript
1
star
71

google-translate-open-api-demo

Objective-C
1
star
72

vue-quick-scroll

a plugin for vue.
Vue
1
star