{"id":13878336,"url":"https://github.com/wikiti/deepl-rb","last_synced_at":"2025-07-16T14:31:56.368Z","repository":{"id":37927975,"uuid":"114039190","full_name":"wikiti/deepl-rb","owner":"wikiti","description":"A simple ruby gem for the DeepL API","archived":true,"fork":false,"pushed_at":"2024-09-20T14:59:31.000Z","size":151,"stargazers_count":67,"open_issues_count":0,"forks_count":15,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-09-23T10:47:48.752Z","etag":null,"topics":["api","deepl","machine-translation","ruby","translator","wrapper-api"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wikiti.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-12T21:06:29.000Z","updated_at":"2024-09-20T15:00:19.000Z","dependencies_parsed_at":"2023-01-17T21:47:34.249Z","dependency_job_id":null,"html_url":"https://github.com/wikiti/deepl-rb","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wikiti%2Fdeepl-rb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wikiti%2Fdeepl-rb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wikiti%2Fdeepl-rb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wikiti%2Fdeepl-rb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wikiti","download_url":"https://codeload.github.com/wikiti/deepl-rb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226138849,"owners_count":17579496,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","deepl","machine-translation","ruby","translator","wrapper-api"],"created_at":"2024-08-06T08:01:46.694Z","updated_at":"2024-11-24T07:30:58.433Z","avatar_url":"https://github.com/wikiti.png","language":"Ruby","readme":"\u003e [!IMPORTANT]\n\u003e This project  has been archived in favour of the [official DeepL ruby gem](https://github.com/DeepLcom/deepl-rb).\n\n[![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)\n\n# DeepL for ruby\n\nA simple ruby wrapper for the [DeepL translation API (v2)](https://www.deepl.com/api.html).\n\n## Installation\n\nInstall this gem with\n\n```sh\ngem install deepl-rb\n# Load it in your ruby file using `require 'deepl'`\n```\n\nOr add it to your Gemfile:\n\n```rb\ngem 'deepl-rb', require: 'deepl'\n```\n\n## Usage\n\nSetup an environment variable named `DEEPL_AUTH_KEY` with your authentication key:\n\n```sh\nexport DEEPL_AUTH_KEY=\"your-api-token\"\n```\n\nAlternatively, you can configure the API client within a ruby block:\n\n```rb\nDeepL.configure do |config|\n  config.auth_key = 'your-api-token'\nend\n```\n\nYou can also configure the API host and the API version:\n\n```rb\nDeepL.configure do |config|\n  config.auth_key = 'your-api-token'\n  config.host = 'https://api-free.deepl.com' # Default value is 'https://api.deepl.com'\n  config.version = 'v1' # Default value is 'v2'\nend\n```\n\n### Available languages\n\nAvailable languages can be retrieved via API:\n\n```rb\nlanguages = DeepL.languages\n\nputs languages.class\n# =\u003e Array\nputs languages.first.class\n# =\u003e DeepL::Resources::Language\nputs \"#{languages.first.code} -\u003e #{languages.first.name}\"\n# =\u003e \"ES -\u003e Spanish\"\n```\n\nNote that source and target languages may be different, which can be retrieved by using the `type`\noption:\n\n```rb\nputs DeepL.languages(type: :source).count\n# =\u003e 24\nputs DeepL.languages(type: :target).count\n# =\u003e 26\n```\n\nAll languages are also defined on the\n[official API documentation](https://www.deepl.com/docs-api/translating-text/).\n\nNote that target languages may include the `supports_formality` flag, which may be checked\nusing the `DeepL::Resources::Language#supports_formality?`.\n\n### Translate\n\nTo translate a simple text, use the `translate` method:\n\n```rb\ntranslation = DeepL.translate 'This is my text', 'EN', 'ES'\n\nputs translation.class\n# =\u003e DeepL::Resources::Text\nputs translation.text\n# =\u003e 'Este es mi texto'\n```\n\nEnable auto-detect source language by skipping the source language with `nil`:\n\n```rb\ntranslation = DeepL.translate 'This is my text', nil, 'ES'\n\nputs translation.detected_source_language\n# =\u003e 'EN'\n```\n\nTranslate a list of texts by passing an array as an argument:\n\n```rb\ntexts = ['Sample text', 'Another text']\ntranslations = DeepL.translate texts, 'EN', 'ES'\n\nputs translations.class\n# =\u003e Array\nputs translations.first.class\n# =\u003e DeepL::Resources::Text\n```\n\nYou can also use custom query parameters, like `tag_handling`, `split_sentences`, `non_splitting_tags` or `ignore_tags`:\n\n```rb\ntranslation = DeepL.translate '\u003cp\u003eA sample\u003c/p\u003e', 'EN', 'ES',\n                              tag_handling: 'xml', split_sentences: false,\n                              non_splitting_tags: 'h1', ignore_tags: %w[code pre]\n\nputs translation.text\n# =\u003e \"\u003cp\u003eUna muestra\u003c/p\u003e\"\n```\n\nThe following parameters will be automatically converted:\n\n| Parameter             | Conversion\n| --------------------- | ---------------\n| `preserve_formatting` | Converts `false` to `'0'` and `true` to `'1'`\n| `split_sentences`     | Converts `false` to `'0'` and `true` to `'1'`\n| `outline_detection`   | Converts `false` to `'0'` and `true` to `'1'`\n| `splitting_tags`      | Converts arrays to strings joining by commas\n| `non_splitting_tags`  | Converts arrays to strings joining by commas\n| `ignore_tags`         | Converts arrays to strings joining by commas\n| `formality`           | No conversion applied\n| `glossary_id`         | No conversion applied\n\n### Glossaries\n\nTo create a glossary, use the `glossaries.create` method. The glossary `entries` argument should be an array of text pairs. Each pair includes the source and the target translations.\n\n```rb\nentries = [\n  ['Hello World', 'Hola Tierra'],\n  ['car', 'auto']\n]\nglossary = DeepL.glossaries.create 'Mi Glosario', 'EN', 'ES', entries\n\nputs glossary.class\n# =\u003e DeepL::Resources::Glossary\nputs glossary.id\n# =\u003e 'aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e'\nputs glossary.entry_count\n# =\u003e 2\n```\n\nCreated glossaries can be used in the `translate` method by specifying the `glossary_id` option:\n\n```rb\ntranslation = DeepL.translate 'Hello World', 'EN', 'ES', glossary_id: 'aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e'\n\nputs translation.class\n# =\u003e DeepL::Resources::Text\nputs translation.text\n# =\u003e 'Hola Tierra'\n\ntranslation = DeepL.translate \"I wish we had a car.\", 'EN', 'ES', glossary_id: 'aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e'\n\nputs translation.class\n# =\u003e DeepL::Resources::Text\nputs translation.text\n# =\u003e Ojalá tuviéramos un auto.\n```\n\nTo list all the glossaries available, use the `glossaries.list` method:\n\n```rb\nglossaries = DeepL.glossaries.list\n\nputs glossaries.class\n# =\u003e Array\nputs glossaries.first.class\n# =\u003e DeepL::Resources::Glossary\n```\n\nTo find an existing glossary, use the `glossaries.find` method:\n\n```rb\nglossary = DeepL.glossaries.find 'aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e'\n\nputs glossary.class\n# =\u003e DeepL::Resources::Glossary\n```\n\nThe glossary resource does not include the glossary entries. To list the glossary entries, use the `glossaries.entries` method:\n\n```rb\nentries = DeepL.glossaries.entries 'aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e'\n\nputs entries.class\n# =\u003e Array\nputs entries.size\n# =\u003e 2\npp entries.first\n# =\u003e [\"Hello World\", \"Hola Tierra\"]\n```\n\nTo delete an existing glossary, use the `glossaries.destroy` method:\n\n```rb\nglossary_id = DeepL.glossaries.destroy 'aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e'\n\nputs glossary_id\n# =\u003e aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e\n```\n\nYou can list all the language pairs supported by glossaries using the `glossaries.language_pairs` method:\n\n```rb\nlanguage_pairs = DeepL.glossaries.language_pairs\n\nputs language_pairs.class\n# =\u003e Array\nputs language_pairs.first.class\n# =\u003e DeepL::Resources::LanguagePair\nputs language_pairs.first.source_lang\n# =\u003e en\nputs language_pairs.first.target_lang\n# =\u003e de\n```\n\n### Monitor usage\n\nTo check current API usage, use:\n\n```rb\nusage = DeepL.usage\n\nputs usage.character_count\n# =\u003e 180118\nputs usage.character_limit\n# =\u003e 1250000\n```\n\n### Handle exceptions\n\nYou can capture and process exceptions that may be raised during API calls. These are all the possible exceptions:\n\n| Exception class | Description |\n| --------------- | ----------- |\n| `DeepL::Exceptions::AuthorizationFailed` | The authorization process has failed. Check your `auth_key` value. |\n| `DeepL::Exceptions::BadRequest` | Something is wrong in your request. Check `exception.message` for more information. |\n| `DeepL::Exceptions::LimitExceeded` | You've reached the API's call limit. |\n| `DeepL::Exceptions::QuotaExceeded` | You've reached the API's character limit. |\n| `DeepL::Exceptions::RequestError` | An unkown request error. Check `exception.response` and `exception.request` for more information. |\n| `DeepL::Exceptions::NotSupported` | The requested method or API endpoint is not supported. |\n\nAn exampling of handling a generic exception:\n\n```rb\ndef my_method\n  item = DeepL.translate 'This is my text', nil, 'ES'\nrescue DeepL::Exceptions::RequestError =\u003e e\n  puts 'Oops!'\n  puts \"Code: #{e.response.code}\"\n  puts \"Response body: #{e.response.body}\"\n  puts \"Request body: #{e.request.body}\"\nend\n```\n\n## Integrations\n\n### Ruby on Rails\n\nYou may use this gem as a standalone service by creating an initializer on your\n`config/initializers` folder with your DeepL configuration. For example:\n\n```rb\n# config/initializers/deepl.rb\nDeepL.configure do |config|\n  # Your configuration goes here\nend\n```\n\nSince the DeepL service is defined globally, you can use service anywhere in your code\n(controllers, models, views, jobs, plain ruby objects… you name it).\n\n### i18n-tasks\n\nYou may also take a look at [`i18n-tasks`](https://github.com/glebm/i18n-tasks), which is a gem\nthat helps you find and manage missing and unused translations. `deepl-rb` is used as one of the\nbackend services to translate content.\n\n## Development\n\nClone the repository, and install its dependencies:\n\n```sh\ngit clone https://github.com/wikiti/deepl-rb\ncd deepl-rb\nbundle install\n```\n\nTo run tests (rspec and rubocop), use\n\n```\nbundle exec rake test\n```\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwikiti%2Fdeepl-rb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwikiti%2Fdeepl-rb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwikiti%2Fdeepl-rb/lists"}