{"id":24540653,"url":"https://github.com/mistralys/deepl-xml-translator","last_synced_at":"2025-06-17T09:06:27.749Z","repository":{"id":38108420,"uuid":"215023430","full_name":"Mistralys/deepl-xml-translator","owner":"Mistralys","description":"Helper class to translate a bundle of strings with or without markup.","archived":false,"fork":false,"pushed_at":"2023-04-19T20:39:46.000Z","size":158,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T16:17:52.759Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Mistralys.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-14T11:15:19.000Z","updated_at":"2023-07-19T07:09:14.000Z","dependencies_parsed_at":"2023-01-28T12:16:34.116Z","dependency_job_id":null,"html_url":"https://github.com/Mistralys/deepl-xml-translator","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fdeepl-xml-translator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fdeepl-xml-translator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fdeepl-xml-translator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fdeepl-xml-translator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mistralys","download_url":"https://codeload.github.com/Mistralys/deepl-xml-translator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249038887,"owners_count":21202803,"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":[],"created_at":"2025-01-22T18:14:32.142Z","updated_at":"2025-04-15T08:42:12.217Z","avatar_url":"https://github.com/Mistralys.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.com/Mistralys/deepl-xml-translator.svg?branch=master)](https://travis-ci.com/Mistralys/deepl-xml-translator)\n\n# DeepL XML Translator\n\nThis is a drop-in PHP helper class that can translate a bundle of strings,\nwhich may contain markup. It uses [DeepL](https://www.deepl.com)'s \n[XML translation feature](https://www.deepl.com/docs-api.html?part=xml), \nand is designed to be very easy to use.\n\n## Installation\n\nSimply require the package in your project via Composer:\n\n```json\n\"require\": {\n    \"mistralys/deepl-xml-translator\" : \"dev-master\"\n}\n```\n\nSee the packagist page: https://packagist.org/packages/mistralys/deepl-xml-translator\n\n## Usage\n\n### Create a new instance of the helper\n\n```php\n$translator = new \\DeeplXML\\Translator(\n    'YourAPIKey', // the DeepL API key to use to connect\n    'EN', // source language\n    'DE' // target language\n); \n```\n\n### Add strings to translate\n\n```php\n$translator-\u003eaddString('string1', 'Please translate me');\n$translator-\u003eaddString('string2', 'Please also translate me');\n```\n\n### Fetch the translation\n\n```php\ntry\n{\n    $translator-\u003etranslate();\n}\ncatch(\\DeeplXML\\Translator_Exception $e)\n{\n    // handle errors\n}    \n```\n\n### Access the translated strings\n\nRetrieving all strings at once:\n\n```php\n$strings = $translator-\u003egetStrings();\n\n foreach($strings as $string)\n {\n     $text = $string-\u003egetTranslatedText();\n }\n```\n\nRetrieving specific strings by ID:\n\n```php\n$string = $translator-\u003egetStringByID('string2');\n$text = $string-\u003egetTranslatedText();\n```\n\n### Ignoring parts of strings\n\nTo avoid parts of strings being translated, the characters to ignore can be\nspecified as needed. They are replaced by placeholders by a simple search \u0026 replace\nbefore sending the translation to DeepL, and restored again afterwards. \n\n```php\n$string = $translator-\u003eaddString('string1', 'Please ignore me');\n\n// the text \"ignore\" will not be translated in the string\n$string-\u003eaddIgnoreString('ignore');\n\n```\n\n## DeepL API connection\n\nThe translator class uses the [SC-Networks/deepl-api-connector](https://github.com/SC-Networks/deepl-api-connector) DeepL API package to connect to the service in the background.\n\nIf you need more advanced features, like translating files and the like, you may use the fully configured connector instance directly:\n\n```php\n$api = $translator-\u003egetConnector();\n\n// do something with it\n```\n\n## Running the tests\n\nBy default, the unit tests will only test the offline API of the Translator itself. To enable live testing with the DeepL API, rename the file `tests/apikey.dist.php` to `tests/apikey.php` and edit it to insert your API key. The additional tests will be enabled automatically.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmistralys%2Fdeepl-xml-translator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmistralys%2Fdeepl-xml-translator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmistralys%2Fdeepl-xml-translator/lists"}