README.md in deepl-rb-2.5.3 vs README.md in deepl-rb-3.0.0
- old
+ new
@@ -1,11 +1,17 @@
-[![Gem Version](https://badge.fury.io/rb/deepl-rb.svg)](https://badge.fury.io/rb/deepl-rb) [![CircleCI](https://circleci.com/gh/wikiti/deepl-rb.svg?style=shield)](https://circleci.com/gh/wikiti/deepl-rb) [![CodeCov](https://codecov.io/gh/wikiti/deepl-rb/branch/master/graph/badge.svg?token=SHLgQNlZ4o)](https://codecov.io/gh/wikiti/deepl-rb)
+[![Gem Version](https://badge.fury.io/rb/deepl-rb.svg)](https://badge.fury.io/rb/deepl-rb)
-# DeepL for ruby
+# DeepL Ruby Library
-A simple ruby wrapper for the [DeepL translation API (v2)](https://www.deepl.com/api.html).
+The [DeepL API](https://developers.deepl.com/docs/api-reference/translate) is a language translation API that allows other computer programs to send texts and documents to DeepL's servers and receive high-quality translations. This opens a whole universe of opportunities for developers: any translation product you can imagine can now be built on top of DeepL's best-in-class translation technology.
+The DeepL Ruby library offers a convenient way for applications written in Ruby to interact with the DeepL API. We intend to support all API functions with the library, though support for new features may be added to the library after they’re added to the API.
+
+## Getting an authentication key
+
+To use the DeepL Ruby Library, you'll need an API authentication key. To get a key, [please create an account here](https://www.deepl.com/pro?utm_source=github&utm_medium=github-ruby-readme#developer). With a DeepL API Free account you can translate up to 500,000 characters/month for free.
+
## Installation
Install this gem with
```sh
@@ -69,11 +75,11 @@
puts DeepL.languages(type: :target).count
# => 26
```
All languages are also defined on the
-[official API documentation](https://www.deepl.com/docs-api/translating-text/).
+[official API documentation](https://developers.deepl.com/docs/api-reference/translate).
Note that target languages may include the `supports_formality` flag, which may be checked
using the `DeepL::Resources::Language#supports_formality?`.
### Translate
@@ -239,22 +245,41 @@
# => 180118
puts usage.character_limit
# => 1250000
```
+### Translate documents
+
+To translate a document, use the `document.translate_document` method. Example:
+
+```rb
+DeepL.document.translate_document('/path/to/spanish_document.pdf', 'ES', 'EN', '/path/to/translated_document.pdf')
+```
+
+The lower level `upload`, `get_status` and `download` methods are also exposed, as well as the convenience method `wait_until_document_translation_finished` on the `DocumentHandle` object, which would replace `get_status`:
+```rb
+doc_handle = DeepL.document.upload('/path/to/spanish_document.pdf', 'ES', 'EN')
+doc_status = doc_handle.wait_until_document_translation_finished # alternatively poll `DeepL.document.get_status`
+# until the `doc_status.successful?`
+DeepL.document.download(doc_handle, '/path/to/translated_document.pdf') unless doc_status.error?
+```
+
### Handle exceptions
You can capture and process exceptions that may be raised during API calls. These are all the possible exceptions:
| Exception class | Description |
| --------------- | ----------- |
| `DeepL::Exceptions::AuthorizationFailed` | The authorization process has failed. Check your `auth_key` value. |
| `DeepL::Exceptions::BadRequest` | Something is wrong in your request. Check `exception.message` for more information. |
+| `DeepL::Exceptions::DocumentTranslationError` | An error occured during document translation. Check `exception.message` for more information. |
| `DeepL::Exceptions::LimitExceeded` | You've reached the API's call limit. |
| `DeepL::Exceptions::QuotaExceeded` | You've reached the API's character limit. |
| `DeepL::Exceptions::RequestError` | An unkown request error. Check `exception.response` and `exception.request` for more information. |
| `DeepL::Exceptions::NotSupported` | The requested method or API endpoint is not supported. |
+| `DeepL::Exceptions::RequestEntityTooLarge` | Your request is too large, reduce the amount of data you are sending. The API has a request size limit of 128 KiB. |
+| `DeepL::Exceptions::ServerError` | An error occured in the DeepL API, wait a short amount of time and retry. |
An exampling of handling a generic exception:
```rb
def my_method
@@ -265,10 +290,79 @@
puts "Response body: #{e.response.body}"
puts "Request body: #{e.request.body}"
end
```
+### Logging
+
+To enable logging, pass a suitable logging object (e.g. the default `Logger` from the Ruby standard library) when configuring the library. The library logs HTTP requests to `INFO` and debug information to `DEBUG`. Example:
+
+```rb
+require 'logger'
+
+logger = Logger.new(STDOUT)
+logger.level = Logger::INFO
+
+deepl.configure do |config|
+ config.auth_key = configuration.auth_key
+ config.logger = logger
+end
+```
+
+### Proxy configuration
+
+To use HTTP proxies, a session needs to be used. The proxy can then be configured as part of the HTTP client options:
+
+```rb
+client_options = HTTPClientOptions.new({ 'proxy_addr' => 'http://localhost', 'proxy_port' => 80 })
+deepl.with_session(client_options) do |session|
+ # ...
+end
+```
+
+### Anonymous platform information
+
+By default, we send some basic information about the platform the client library is running on with each request, see [here for an explanation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent). This data is completely anonymous and only used to improve our product, not track any individual users. If you do not wish to send this data, you can opt-out by setting the `send_platform_info` flag in the configuration to `false` like so:
+
+```rb
+deepl.configure({}, nil, nil, false) do |config|
+ # ...
+end
+```
+
+You can also complete customize the `User-Agent` header like so:
+
+```rb
+deepl.configure do |config|
+ config.user_agent = 'myCustomUserAgent'
+end
+```
+
+### Sending multiple requests
+
+When writing an application that send multiple requests, using a HTTP session will give better performance through [HTTP Keep-Alive](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive). You can use it by simply wrapping your requests in a `with_session` block:
+
+```rb
+deepl.with_session do |session|
+ deepl.translate(sentence1, 'DE', 'EN-GB')
+ deepl.translate(sentence2, 'DE', 'EN-GB')
+ deepl.translate(sentence3, 'DE', 'EN-GB')
+end
+```
+
+### Writing a plugin
+
+If you use this library in an application, please identify the application by setting the name and version of the plugin:
+
+```rb
+deepl.configure({}, 'MyTranslationPlugin', '1.0.1') do |config|
+ # ...
+end
+```
+
+This information is passed along when the library makes calls to the DeepL API. Both name and version are required. Please note that setting the `User-Agent` header via `deepl.configure` will override this setting, if you need to use this, please manually identify your Application in the `User-Agent` header.
+
## Integrations
### Ruby on Rails
You may use this gem as a standalone service by creating an initializer on your
@@ -293,15 +387,31 @@
## Development
Clone the repository, and install its dependencies:
```sh
-git clone https://github.com/wikiti/deepl-rb
+git clone https://github.com/DeepLcom/deepl-rb
cd deepl-rb
bundle install
```
To run tests (rspec and rubocop), use
```
bundle exec rake test
```
+
+### Caution: Changing VCR Tests
+
+If you need to rerecord some of the VCR tests, simply setting `record: :new_episodes` and rerunning `rspec` won't be enough in some cases, specifically around document translation (due to its statefulness) and glossaries (since a glossary ID is associated with a specific API account).
+For example, there are document translations tests that split up the `upload`, `get_status` and `download` calls into separate test cases. You need to first rerecord the `upload` call, you can do execute a single test like this (the line should be where the `it` block of the test starts):
+
+```sh
+rspec ./spec/api/deepl_spec.rb:152
+```
+
+This will return a `document_id` and a `document_key`, you will need to update the values in the `get_status` and `download` tests accordingly. You can find examples for this in the git history.
+Similarly, for the glossary tests you will need to delete the recorded HTTP requests for certain glossary IDs so that `rspec` will create the glossaries on your account instead. Feel free to reach out on our discord if you run into any trouble here.
+
+## Acknowledgements
+
+This library was originally developed by [Daniel Herzog](mailto:info@danielherzog.es), we are grateful for his contributions. Beginning with v3.0.0, DeepL took over development and officially supports and maintains the library together with Daniel.
\ No newline at end of file