Gem Version Dependency Status CircleCI

DeepL for ruby

A simple ruby wrapper for the DeepL translation API (v1).

Installation

Install this gem with

gem install deepl-rb

Or add it to your Gemfile:

gem 'deepl-rb'

Usage

Setup an environment variable named DEEPL_AUTH_KEY with your authentication key:

export DEEPL_AUTH_KEY="your-api-token"

Alternatively, you can configure the API client within a ruby block:

DeepL.configure do |config|
  config.auth_key = 'your-api-token'
end

You can also configure the api host:

DeepL.configure do |config|
  config.auth_key = 'your-api-token'
  config.host = 'https://test-api.deepl.com' # Default value is 'https://api.deepl.com'
end

Translate

To translate a simple text, use the translate method:

item = DeepL.translate 'This is my text', 'EN', 'ES'

puts item.class
# => DeepL::Resources::Text
puts item.text
# => 'Este es mi texto'

You can also auto-detect source language by skipping it with nil:

item = DeepL.translate 'This is my text', nil, 'ES'

puts item.detected_source_language
# => 'EN'

You can also translate a list of texts by passing an array as an argument:

texts = ['Sample text', 'Another text']
items = DeepL.translate texts, 'EN', 'ES'

puts items.class
# => Array
puts items.first.class
# => DeepL::Resources::Text

Development

Clone the repository, and install its dependencies:

git clone https://github.com/wikiti/deepl-rb
cd deepl-rb
bundle install

To run tests (rspec and rubocop), use

bundle exec rake test

Contributors

This project has been developed by:

Avatar Name Nickname Email
Daniel Herzog Wikiti [email protected]