BabelI18n

This Ruby library allows to translate files locale dictionaries and provides methods to translate words and phrases using the Google Translate API

Installation

Add this line to your application's Gemfile:

gem 'babel_i18n'

And then execute:

$ bundle

Or install it yourself as:

$ gem install babel_i18n

Google API Key

This GEM requires a valid Google API key for all requests

To find your application's API key, do the following:

  1. Go to the Google Developers Console.
  2. Select a project, or create a new one.
  3. In the sidebar on the left, expand APIs & auth. Next, click APIs. Select the Enabled APIs link in the API section to see a list of all your enabled APIs. Make sure that the Google Translate API is on the list of enabled APIs. If you have not enabled it, select the API from the list of APIs, then select the Enable API button for the API.
  4. In the sidebar on the left, select Credentials.

Usage

Translate file locale dictionary

Command line

$ babel_i18n translate_file en.yml --to pt-BR --key YOUR_GOOGLE_API_KEY

Or set GOOGLE_API_KEY Environment Variable

$ export GOOGLE_API_KEY=YOUR_GOOGLE_API_KEY
$ babel_i18n translate_file en.yml --to pt-BR

Translate words and phrases

Command line

$ babel_i18n translate_text Hi --from en --to pt-BR --key YOUR_GOOGLE_API_KEY

Or set GOOGLE_API_KEY Environment Variable

$ export GOOGLE_API_KEY=YOUR_GOOGLE_API_KEY
$ babel_i18n translate_text Hi --to pt-BR

In your ruby application

BabelI18n::Base.new('Hi', ENV['GOOGLE_API_KEY']).from('en').to('pt-BR').translate
=> "Oi"

Detecting language, omitting parameter 'from'

BabelI18n::Base.new('Hi', ENV['GOOGLE_API_KEY']).to('pt-BR').translate
=> "Oi"

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake rspec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/gabrielpedepera/babel_i18n.

License

The gem is available as open source under the terms of the MIT License.