• Stars
    star
    330
  • Rank 127,657 (Top 3 %)
  • Language
    Ruby
  • Created over 14 years ago
  • Updated 8 months ago

Reviews

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

Repository Details

Google Translate (with Bulk translate) in Ruby

EasyTranslate

Build Status

This is a Ruby library for Google Translate that makes working with bulk calls, user_ips and access via API Key easy.


Installation

$ gem install easy_translate

Or in your Gemfile:

gem 'easy_translate'

Single translation

# auto-detect
EasyTranslate.translate('Hello, world', to: :spanish) # => "Hola, mundo"
EasyTranslate.translate('Hello, world', to: 'es') # => "Hola, mundo"

# feel free to specify explicitly
EasyTranslate.translate('Hola, mundo', from: :spanish, to: :en) # => "Hello, world"

Batch translation (Yay!)

# multiple strings
EasyTranslate.translate(['Hello', 'Goodbye'], to: :spanish) # => ["Β‘Hola", "Despedida"]

API Keys

# make google happy - (NOTE: use these anywhere)
EasyTranslate.translate('Hello, world', to: :es, key: 'xxx')

# don't want to set the key on every call? ** Me either! **
EasyTranslate.api_key = 'xxx'

You want language detection too?

# detect language
EasyTranslate.detect "This is definitely English!" # => 'en'

Batch detection (Woohoo!)

# detect language
EasyTranslate.detect ['Hello World', 'ζˆ‘ε§“θ­š'] # => ['en', 'zh-CN']

Need confidence in your detections?

# detect language with confidence
EasyTranslate.detect "This is definitely English!", confidence: true # => { :language => 'en', :confidence => 0.77272725 }
# detect batch languages with confidence
EasyTranslate.detect ['This is definitely English!', 'ζˆ‘ε§“θ­š'], confidence: true # => [{ :language => 'en', :confidence => 0.77272725 }, { :language => 'zh-CN', :confidence => 1.0 }]

Explicitly select translation model (NMT, PBMT)

Google Translate now replaces Phrase Based Machine Translation (PBMT) with Neural Machine Translation (NMT) automatically where possible. If you prefer PBMT or need to compare the results, you can use the model: parameter with either nmt or base to force the model selection:

EasyTranslate.translate("El cuervo americano es un ave con plumas negras iridiscentes sobre todo su cuerpo.", from: "es", to: "en", model: "nmt")
 # => "The American Raven is a bird with iridescent black feathers over its entire body."
EasyTranslate.translate("El cuervo americano es un ave con plumas negras iridiscentes sobre todo su cuerpo.", from: "es", to: "en", model: "base")
# => "The American crow is a bird with iridescent black feathers over her body."

See https://research.googleblog.com/2016/09/a-neural-network-for-machine.html for more background

Google Translate supports HTML (default) and plain text formats

EasyTranslate.translate "Las doce en punto", format: 'text', to: :en
# => "Twelve o'clock"
EasyTranslate.translate "Las doce <b>en punto</b>", format: 'html', to: :en
# => "Twelve <b>o&#39;clock</b>"

A note on concurrency as of v0.4.0

Due to limitations with the Google Translate batch API, above a certain number of translations - this library will begin making calls concurrently.

The default concurrency is 4, but if you'd prefer to run without threads, you can set :concurrency => 1 to run the translation calls serially.


List of languages

# list from <http://translate.google.com/>
EasyTranslate::LANGUAGES # => { 'en' => 'english', ... }

List of supported languages

# List all languages (from API)
EasyTranslate.translations_available

# List all languages supported by some language
EasyTranslate.translations_available('zh-CN')

EasyTranslate in PHP

Kofel ported this library to PHP. You can find the port on GitHub


Contributors

Full contributor data at: https://github.com/seejohnrun/easy_translate/contributors


License

(The MIT License)

Copyright Β© 2010-2018 John Crepezzi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the β€˜Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED β€˜AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

google_plus

Google+ Ruby Gem
Ruby
163
star
2

prelude

ActiveRecord custom preloading
Ruby
88
star
3

database_validation

Automatic Rails validations from your database
Ruby
62
star
4

track_history

Smart, performant auditing of ActiveRecord models
Ruby
60
star
5

gotcha

Smart Captcha Automation
Ruby
58
star
6

console_tweet

Simple CLI Twitter Client
Ruby
52
star
7

web

HTTP response caching
Ruby
52
star
8

vain

Check github watchers
Ruby
35
star
9

dotfiles

Shell
31
star
10

php-statsd

simple statsd library and CI spark
PHP
30
star
11

sparks

A package management system for CodeIgniter
PHP
25
star
12

proxy_record

Ruby
22
star
13

flexible_api

Ruby
21
star
14

redis-repeater

Automatically transfer items in queues on one Redis machine to another
Ruby
16
star
15

htmlcov-example

an example for setting up mocha & html-cov
JavaScript
12
star
16

indeed_api

Ruby wrapper for the Indeed Job search API
Ruby
11
star
17

cereal_eyes

CerealEyes is a Ruby serialization library similar to GSON
Ruby
10
star
18

flexible_api_server

Ruby
9
star
19

botsy

Ruby Campfire Bot
Ruby
9
star
20

nice_http

A nice, testable HTTP library for PHP
PHP
8
star
21

delocalize

Automatically pull localized text out into YAML files
Ruby
8
star
22

tweetStream4J

Java bindings for the Twitter Streaming API
Java
7
star
23

talks

5
star
24

plan

simple command-line todo-list manager
Ruby
5
star
25

locale_base

Easy language translation for YAML locale files - and other nested ruby objects
Ruby
5
star
26

weatherbug

Ruby Weatherbug Partner API Wrapper
Ruby
4
star
27

laze

javascript lazy properties
JavaScript
4
star
28

Pretty-Damn-Fancy

Java PDF Brute Force Cracker
Java
4
star
29

coup

online coup board
HTML
4
star
30

php-tweet

Upcoming Twitter Library for PHP
PHP
3
star
31

Open-Stanza

Engine that powers socialstanza.com - a poetry site
Ruby
3
star
32

roflscale

Make everything scale infinitely.
Ruby
3
star
33

gravatar_helper

Simple CodeIgniter Gravatar Helper
PHP
3
star
34

columnizer

Easily put multi-dimensional arrays into columns
Ruby
3
star
35

qr-scanner

JavaScript
3
star
36

my_tunes

Music Library Broadcasting
Ruby
3
star
37

io-statsd

a StatsD client for Io
Io
2
star
38

canvaspong

HTML Canvas Pong
2
star
39

seejohnrun.github.io

CSS
2
star
40

iou

Io
1
star
41

git-help

1
star
42

quick_short

Short URL library with some special tricks
Ruby
1
star
43

governor

JavaScript
1
star
44

view_something

Easily use SQL views alongside ActiveRecord
Ruby
1
star
45

restful_documentation

Ruby
1
star
46

settings

simple javascript settings object
JavaScript
1
star
47

john-spark

1
star
48

succeed

JavaScript
1
star
49

rstack

Ruby Stack Overflow API Wrapper
Ruby
1
star
50

shell_command

shell_command tries to provide a better interface for communicating with commands you spawn on the shell.
Ruby
1
star
51

socktalk

socket.io-proxy
JavaScript
1
star
52

dependable

Dependable Dependency Calculation
Ruby
1
star
53

refined_colors

simple CLI colors via refinements
Ruby
1
star
54

iolog

A small logging library for Io
Io
1
star
55

likewise

Ruby
1
star