Coder Social home page Coder Social logo

easy_translate's Introduction

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 }]

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-2011 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.

easy_translate's People

Contributors

seejohnrun avatar glebm avatar gmaliar avatar henrik avatar petergoldstein avatar zetaben avatar codegoalie avatar hemancuso avatar mariusandra avatar prurph avatar nel avatar

Watchers

James Cloos avatar  avatar

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.