From 21c4ca3243635b0a0ccd82838a45ad75ae03305a Mon Sep 17 00:00:00 2001 From: Jay Trees Date: Thu, 9 Dec 2021 14:47:12 +0100 Subject: [PATCH 01/14] Auto detect input language as default --- README.md | 4 ++-- src/DeepL.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9c427f3..6117b52 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ foreach ($translations as $translation) { | param | Description | |---------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | $text | Text to be translated. Only UTF8-encoded plain text is supported. The parameter may be specified as an Array and translations are returned in the same order as they are requested. Each of the array values may contain multiple sentences. Up to 50 texts can be sent for translation in one request. | -| $sourceLang | Language of the text to be translated.
default: de | +| $sourceLang | Language of the text to be translated.
default: "" (DeepL will auto-detect) | | $targetLang | The language into which the text should be translated.
default: en | | $tagHandling | Sets which kind of tags should be handled. Options currently available: "xml" | | $ignoreTags | Array of XML tags that indicate text not to be translated.
default: null | @@ -110,7 +110,7 @@ You can now check how much you translate, as well as the limit: $usageArray = $deepl->usage(); echo 'You have used '.$usageArray['character_count'].' of '.$usageArray['character_limit'].' in the current billing period.'.PHP_EOL; - + ``` ### Glossary diff --git a/src/DeepL.php b/src/DeepL.php index 212dd57..94fe9b0 100644 --- a/src/DeepL.php +++ b/src/DeepL.php @@ -73,7 +73,7 @@ public function languages($type = null) */ public function translate( $text, - $sourceLang = 'de', + $sourceLang = '', $targetLang = 'en', $tagHandling = null, array $ignoreTags = null, From 5d9fbef65f625449d686ede93759b4252a71688a Mon Sep 17 00:00:00 2001 From: vims Date: Wed, 27 Apr 2022 17:07:28 +0200 Subject: [PATCH 02/14] Skip GlossaryTest when noch authKey is set --- tests/integration/GlossaryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/GlossaryTest.php b/tests/integration/GlossaryTest.php index dc98871..9108051 100644 --- a/tests/integration/GlossaryTest.php +++ b/tests/integration/GlossaryTest.php @@ -25,7 +25,7 @@ public static function setUpBeforeClass(): void $authKey = getenv('DEEPL_AUTH_KEY'); if ($authKey === false) { - return; + self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.'); } self::$authKey = $authKey; From fbca5453683782c819528319ac26c5bd9b4ce070 Mon Sep 17 00:00:00 2001 From: vims Date: Wed, 27 Apr 2022 17:07:28 +0200 Subject: [PATCH 03/14] Skip GlossaryTest when no authKey is set --- tests/integration/GlossaryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/GlossaryTest.php b/tests/integration/GlossaryTest.php index dc98871..9108051 100644 --- a/tests/integration/GlossaryTest.php +++ b/tests/integration/GlossaryTest.php @@ -25,7 +25,7 @@ public static function setUpBeforeClass(): void $authKey = getenv('DEEPL_AUTH_KEY'); if ($authKey === false) { - return; + self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.'); } self::$authKey = $authKey; From 5facac4bc816d902dd47177959bdc29b9268a68d Mon Sep 17 00:00:00 2001 From: vims Date: Wed, 27 Apr 2022 17:26:17 +0200 Subject: [PATCH 04/14] Add $glossaryId to translate-Function as requested by @larzuk91 and @KaiOnGitHub Add PHP 8.1 to composer.json and travis.yml --- .travis.yml | 1 + composer.json | 2 +- src/DeepL.php | 5 ++++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e42501b..7dd1847 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ matrix: - php: 7.3 - php: 7.4 - php: 8.0 + - php: 8.1 - php: nightly allow_failures: - php: nightly diff --git a/composer.json b/composer.json index 9b0857a..50039fa 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ } ], "require": { - "php": ">=7.3 <8.1", + "php": ">=7.3 <8.2", "ext-json": "*", "ext-curl": "*" }, diff --git a/src/DeepL.php b/src/DeepL.php index 212dd57..e4a76f6 100644 --- a/src/DeepL.php +++ b/src/DeepL.php @@ -64,6 +64,7 @@ public function languages($type = null) * @param array|null $nonSplittingTags * @param null $outlineDetection * @param array|null $splittingTags + * @param string|null $glossaryId * * @return array * @@ -82,7 +83,8 @@ public function translate( $preserveFormatting = null, array $nonSplittingTags = null, $outlineDetection = null, - array $splittingTags = null + array $splittingTags = null, + string $glossaryId = null ) { if (is_array($tagHandling)) { throw new InvalidArgumentException('$tagHandling must be of type String in V2 of DeepLLibrary'); @@ -99,6 +101,7 @@ public function translate( 'split_sentences' => $splitSentences, 'preserve_formatting' => $preserveFormatting, 'outline_detection' => $outlineDetection, + 'glossary_id' => $glossaryId ); $paramsArray = $this->removeEmptyParams($paramsArray); From efc1007e554e4ac3bc4756b283246377fe8e6d03 Mon Sep 17 00:00:00 2001 From: vims Date: Thu, 28 Apr 2022 09:58:53 +0200 Subject: [PATCH 05/14] Update composer.json for PHP 8.1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 50039fa..be3ed61 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "babymarkt/deepl-php-lib", "type": "library", - "description": "DeepL API Client Library supporting PHP >= 7.3 && PHP < 8.1", + "description": "DeepL API Client Library supporting PHP >= 7.3 && PHP <= 8.1", "keywords": [ "babymarkt", "deepl", From f8ec91a47a1a72f67b715b2f219f11c7f949f41c Mon Sep 17 00:00:00 2001 From: vims Date: Thu, 28 Apr 2022 10:01:33 +0200 Subject: [PATCH 06/14] Migrate phpunit.xml.dist because phpunit-Warning. --- phpunit.xml.dist | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b1e3381..9c1a135 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,19 +1,17 @@ - - - - - tests/ - - - - - - src/ - - - - - - - \ No newline at end of file + + + + src/ + + + + + + + + tests/ + + + + From 8ddac25993d5382ebe98749fd1253b9e93b3e97c Mon Sep 17 00:00:00 2001 From: vims Date: Thu, 28 Apr 2022 10:34:02 +0200 Subject: [PATCH 07/14] - Add ability to run integration-Test against both Free and Pro Api-Urls. - probably fix testWithProxy, but i need a proxy to test it --- tests/integration/DeepLApiTest.php | 54 ++++++++++++++++++------------ tests/integration/GlossaryTest.php | 21 ++++++++---- 2 files changed, 47 insertions(+), 28 deletions(-) diff --git a/tests/integration/DeepLApiTest.php b/tests/integration/DeepLApiTest.php index dffdc6b..05fe863 100644 --- a/tests/integration/DeepLApiTest.php +++ b/tests/integration/DeepLApiTest.php @@ -22,6 +22,12 @@ class DeepLApiTest extends TestCase */ protected static $authKey = false; + /** + * DeepL Auth Key. + * + * @var string + */ + protected static $apiHost; /** * Proxy URL * @var bool|string @@ -42,6 +48,7 @@ public static function setUpBeforeClass(): void parent::setUpBeforeClass(); $authKey = getenv('DEEPL_AUTH_KEY'); + $apiHost = getenv('DEEPL_HOST') ?: 'api.deepl.com'; $proxy = getenv('HTTP_PROXY'); $proxyCredentials = getenv('HTTP_PROXY_CREDENTIALS'); @@ -49,8 +56,9 @@ public static function setUpBeforeClass(): void return; } - self::$authKey = $authKey; - self::$proxy = $proxy; + self::$authKey = $authKey; + self::$apiHost = $apiHost; + self::$proxy = $proxy; self::$proxyCredentials = $proxyCredentials; } @@ -82,7 +90,7 @@ public function testTranslateSuccess() self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.'); } - $deepl = new DeepL(self::$authKey); + $deepl = new DeepL(self::$authKey, 2, self::$apiHost); $germanText = 'Hallo Welt'; $expectedText = 'Hello world'; @@ -101,7 +109,7 @@ public function testTranslateV1Success() self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.'); } - $deepl = new DeepL(self::$authKey, 1); + $deepl = new DeepL(self::$authKey, 1, self::$apiHost); $germanText = 'Hallo Welt'; $expectedText = 'Hello world'; @@ -120,7 +128,7 @@ public function testTranslateWrongVersion() self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.'); } $germanText = 'Hallo Welt'; - $deepl = new DeepL(self::$authKey, 3); + $deepl = new DeepL(self::$authKey, 3, self::$apiHost); $this->expectException('\BabyMarkt\DeepL\DeepLException'); @@ -136,7 +144,7 @@ public function testTranslateTagHandlingSuccess() self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.'); } - $deepl = new DeepL(self::$authKey); + $deepl = new DeepL(self::$authKey, 2, self::$apiHost); $englishText = 'text to translate'; $expectedText = 'zu übersetzender Text'; @@ -160,7 +168,7 @@ public function testTranslateIgnoreTagsSuccess() self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.'); } - $deepl = new DeepL(self::$authKey); + $deepl = new DeepL(self::$authKey, 2, self::$apiHost); $englishText = 'text to do not translate

text to translate

'; $expectedText = 'text to do not translate

zu übersetzender Text

'; @@ -185,7 +193,7 @@ public function testUsage() self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.'); } - $deepl = new DeepL(self::$authKey); + $deepl = new DeepL(self::$authKey, 2, self::$apiHost); $response = $deepl->usage(); self::assertArrayHasKey('character_count', $response); @@ -201,7 +209,7 @@ public function testLanguages() self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.'); } - $deepl = new DeepL(self::$authKey); + $deepl = new DeepL(self::$authKey, 2, self::$apiHost); $response = $deepl->languages(); foreach ($response as $language) { @@ -219,7 +227,7 @@ public function testLanguagesSource() self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.'); } - $deepl = new DeepL(self::$authKey); + $deepl = new DeepL(self::$authKey, 2, self::$apiHost); $response = $deepl->languages('source'); foreach ($response as $language) { @@ -237,7 +245,7 @@ public function testLanguagesTarget() self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.'); } - $deepl = new DeepL(self::$authKey); + $deepl = new DeepL(self::$authKey, 2, self::$apiHost); $response = $deepl->languages('target'); foreach ($response as $language) { @@ -255,7 +263,7 @@ public function testLanguagesFail() self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.'); } - $deepl = new DeepL(self::$authKey); + $deepl = new DeepL(self::$authKey, 2, self::$apiHost); $this->expectException('\BabyMarkt\DeepL\DeepLException'); @@ -271,7 +279,7 @@ public function testTranslateWithAllParams() self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.'); } - $deepl = new DeepL(self::$authKey); + $deepl = new DeepL(self::$authKey, 2, self::$apiHost); $englishText = 'text to do not translate

please translate this text

'; $expectedText = 'text to do not translate

bitte übersetzen Sie diesen Text

'; @@ -303,13 +311,15 @@ public function testWithProxy() } if (self::$proxy === false) { - // The test would succeed with $proxy === false but it wouln't mean anything. + // The test would succeed with $proxy === false but it wouldn't mean anything. $this->markTestSkipped('Proxy is not configured.'); } - $deepl = new DeepL(self::$authKey); - $deepl->setProxy(self::$proxy); - $deepl->setProxyCredentials(self::$proxyCredentials); + $client = new Client(self::$authKey, 2, self::$apiHost); + $client->setProxy(self::$proxy); + $client->setProxyCredentials(self::$proxyCredentials); + + $deepl = new DeepL(self::$authKey, 2, self::$apiHost, $client); $englishText = 'please translate this text'; $expectedText = 'Bitte übersetzen Sie diesen Text'; @@ -345,7 +355,7 @@ public function testTranslateFormality() self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.'); } - $deepl = new DeepL(self::$authKey); + $deepl = new DeepL(self::$authKey, 2, self::$apiHost); $englishText = 'text to do not translate

please translate this text

'; $expectedText = 'Nicht zu übersetzender Text

Bitte übersetze diesen Text

'; @@ -370,7 +380,7 @@ public function testTranslateWithHTML() self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.'); } - $deepl = new DeepL(self::$authKey); + $deepl = new DeepL(self::$authKey, 2, self::$apiHost); $textToTranslate = array( 'Hello WorldThis should stay the same', 'Another Text
new line

this is a paragraph

' @@ -383,7 +393,7 @@ public function testTranslateWithHTML() ), array( 'detected_source_language' => "EN", - 'text' => "Eine weitere
neue Textzeile

, die ein Absatz ist


", + 'text' => "Eine weitere
neue Textzeile

, dies ist ein Absatz


", ), ); @@ -414,7 +424,7 @@ public function testTranslateWithNotSupportedSourceLanguage() self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.'); } - $deepl = new DeepL(self::$authKey); + $deepl = new DeepL(self::$authKey, 2, self::$apiHost); $this->expectException('\BabyMarkt\DeepL\DeepLException'); $deepl->translate('some txt', 'dk', 'de'); @@ -429,7 +439,7 @@ public function testTranslateWithNotSupportedDestinationLanguage() self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.'); } - $deepl = new DeepL(self::$authKey); + $deepl = new DeepL(self::$authKey, 2, self::$apiHost); $this->expectException('\BabyMarkt\DeepL\DeepLException'); $deepl->translate('some txt', 'en', 'dk'); diff --git a/tests/integration/GlossaryTest.php b/tests/integration/GlossaryTest.php index 9108051..aa6e13f 100644 --- a/tests/integration/GlossaryTest.php +++ b/tests/integration/GlossaryTest.php @@ -15,6 +15,13 @@ class GlossaryTest extends TestCase */ protected static $authKey = false; + /** + * DeepL Auth Key. + * + * @var string + */ + protected static $apiHost; + /** * Setup DeepL Auth Key. */ @@ -23,17 +30,19 @@ public static function setUpBeforeClass(): void parent::setUpBeforeClass(); $authKey = getenv('DEEPL_AUTH_KEY'); + $apiHost = getenv('DEEPL_HOST') ?: 'api.deepl.com'; if ($authKey === false) { self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.'); } self::$authKey = $authKey; + self::$apiHost = $apiHost; } public static function tearDownAfterClass(): void { - $glossaryAPI = new Glossary(self::$authKey); + $glossaryAPI = new Glossary(self::$authKey, 2, self::$apiHost); $glossariesResponse = $glossaryAPI->listGlossaries(); @@ -62,7 +71,7 @@ public function testCreateGlossary() self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.'); } - $deepl = new Glossary(self::$authKey); + $deepl = new Glossary(self::$authKey, 2, self::$apiHost); $entries = ['Hallo' => 'Hello']; $glossary = $deepl->createGlossary('test', $entries, 'de', 'en'); @@ -80,7 +89,7 @@ public function testListGlossaries() self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.'); } - $deepl = new Glossary(self::$authKey); + $deepl = new Glossary(self::$authKey, 2, self::$apiHost); $glossaries = $deepl->listGlossaries(); self::assertNotEmpty($glossaries['glossaries']); @@ -97,7 +106,7 @@ public function testGlossaryInformation($glossaryId) self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.'); } - $deepl = new Glossary(self::$authKey); + $deepl = new Glossary(self::$authKey, 2, self::$apiHost); $information = $deepl->glossaryInformation($glossaryId); self::assertArrayHasKey('glossary_id', $information); @@ -114,7 +123,7 @@ public function testGlossaryEntries($glossaryId) self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.'); } - $deepl = new Glossary(self::$authKey); + $deepl = new Glossary(self::$authKey, 2, self::$apiHost); $entries = $deepl->glossaryEntries($glossaryId); self::assertEquals($entries, ['Hallo' => 'Hello']); @@ -131,7 +140,7 @@ public function testDeleteGlossary($glossaryId) self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.'); } - $deepl = new Glossary(self::$authKey); + $deepl = new Glossary(self::$authKey, 2, self::$apiHost); $response = $deepl->deleteGlossary($glossaryId); self::assertNull($response); From 2e9eee088b0a0c1f00de92d5b2aab1a92f4ecde6 Mon Sep 17 00:00:00 2001 From: vims Date: Thu, 28 Apr 2022 15:47:39 +0200 Subject: [PATCH 08/14] Update README.md, CHANGELOG.md and LICENSE.md --- CHANGELOG.md | 10 ++++++++++ LICENSE.md | 2 +- README.md | 49 +++++++++++++++++++++++++++++++++---------------- 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 684f1a7..1940120 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [3.1.0] - 2022-29-04 +### Added +- PHP 8.1 compatibility +- glossary_id to translate-method +- ability to run Integration-Tests against custom host if needed (Free/Pro) +### Changed +- migrated phpunit.xml.dist +- fixed some Tests and general Maintenance such as Typos in README.md +### Removed + ## [3.0.1] - 2021-07-09 ### Added ### Changed diff --git a/LICENSE.md b/LICENSE.md index 7c0b357..0dbdf02 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ # The MIT License (MIT) -Copyright (c) 2019 babymarkt.de GmbH +Copyright (c) 2018-2022 babymarkt.de GmbH > Permission is hereby granted, free of charge, to any person obtaining a copy > of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 90dba14..40a0008 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,20 @@ -# deepl-php-lib +# deepl-php-lib - +*** +## Deprecated Library ! +Hello everyone, + +in the last couple of months we didn't give much attention to this projekt. DeepL on the other hand has developed client libraries for Python, .NET and Node.js (see: [API-Doc][link-deepl-client-libraries]). + +Since there is a PHP-Library in the works [Github][link-deepl-php-lib-github] and our track record with maintaining our library hasn't been as good as it should have been, we decided to abandon this library and switch internally to the official one. + +To make clear that we won't continue to work on this repository, we will archive it. If anyone from the community wants to continue our work we can put a line in the README to point to the new maintained repository. + +Otherwise, we recommend you to check out the new library coming from [DeepL][link-deepl-php-lib-github]. + +Thank you to everyone who contributed to this project over the years. + +*** [![Latest Version on Packagist][ico-version]][link-packagist] [![Software License][ico-license]](LICENSE.md) [![Build Status][ico-travis]][link-travis] @@ -123,21 +138,21 @@ Create a glossary $glossary = $deepl->createGlossary('MyGlossary', ['Hallo' => 'Hello'], 'de', 'en'); ``` -| param | Description | -|---------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| $name | Glossary name -| $entries | Array of entries -| $sourceLanguage | The source language into which the glossary rule apply | -| $targetLanguage | The target language into which the glossary rule apply | +| param | Description | +|-----------------|--------------------------------------------------------| +| $name | Glossary name | +| $entries | Array of entries | +| $sourceLanguage | The source language into which the glossary rule apply | +| $targetLanguage | The target language into which the glossary rule apply | Delete a glossary ```php $glossary = $deepl->deleteGlossary($glossaryId); ``` -| param | Description | -|---------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| $glossaryId | Glossary uuid (set by DeepL when glossary is created) +| param | Description | +|-------------|-------------------------------------------------------| +| $glossaryId | Glossary uuid (set by DeepL when glossary is created) | List glossaries ```php @@ -157,9 +172,9 @@ $glossaryInformation = $deepl->glossaryInformation($glossaryId); var_dump($glossaryInformation); ``` -| param | Description | -|---------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| $glossaryId | Glossary uuid (set by DeepL when glossary is created) +| param | Description | +|-------------|-------------------------------------------------------| +| $glossaryId | Glossary uuid (set by DeepL when glossary is created) | Get glossary entries ```php @@ -169,9 +184,9 @@ foreach ($entries as $sourceLangText => $targetLangText) { } ``` -| param | Description | -|---------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| $glossaryId | Glossary uuid (set by DeepL when glossary is created) +| param | Description | +|-------------|-------------------------------------------------------| +| $glossaryId | Glossary uuid (set by DeepL when glossary is created) | ### Configuring cURL requests If you need to use a proxy, you can configure the underlying curl client to use one. You can also specify a timeout to avoid waiting for several minutes if Deepl is unreachable @@ -231,3 +246,5 @@ The MIT License (MIT). Please see [License File](LICENSE.md) for more informatio [link-author]: https://github.com/Baby-Markt [link-contributors]: ../../contributors [link-deepl]: https://www.deepl.com/docs-api/introduction/ +[link-deepl-client-libraries]:https://www.deepl.com/en/docs-api/accessing-the-api/client-libraries/ +[link-deepl-php-lib-github]:https://github.com/DeepLcom/deepl-php From e2902ed01a9a22f03e8f6a0b5ca09f8b7e0db1c3 Mon Sep 17 00:00:00 2001 From: vims Date: Fri, 29 Apr 2022 09:26:46 +0200 Subject: [PATCH 09/14] Change api.deepl.com' to api-free.deepl.com for next Major release --- README.md | 4 ++-- src/Client.php | 2 +- src/DeepL.php | 4 +--- src/Glossary.php | 2 +- tests/integration/DeepLApiTest.php | 2 +- tests/integration/GlossaryTest.php | 2 +- 6 files changed, 7 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 40a0008..de2ed69 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# deepl-php-lib - +# deepl-php-lib *** ## Deprecated Library ! @@ -54,7 +54,7 @@ Use the DeepL API Pro: use \BabyMarkt\DeepL\DeepL; $authKey = ''; -$deepl = new DeepL($authKey,2,'api.deepl.com'); +$deepl = new DeepL($authKey,2,'api-free.deepl.com'); ``` ### Translate diff --git a/src/Client.php b/src/Client.php index 18045df..afc6646 100644 --- a/src/Client.php +++ b/src/Client.php @@ -71,7 +71,7 @@ final class Client implements ClientInterface * @param integer $apiVersion * @param string $host */ - public function __construct($authKey, $apiVersion = 2, $host = 'api.deepl.com') + public function __construct($authKey, $apiVersion = 2, $host = 'api-free.deepl.com') { $this->authKey = $authKey; $this->apiVersion = $apiVersion; diff --git a/src/DeepL.php b/src/DeepL.php index e4a76f6..0cf846d 100644 --- a/src/DeepL.php +++ b/src/DeepL.php @@ -6,8 +6,6 @@ /** * DeepL API client library - * - * @package BabyMarkt\DeepL */ class DeepL { @@ -26,7 +24,7 @@ class DeepL */ private $client; - public function __construct($authKey, $apiVersion = 2, $host = 'api.deepl.com', ClientInterface $client = null) + public function __construct($authKey, $apiVersion = 2, $host = 'api-free.deepl.com', ClientInterface $client = null) { $this->client = $client ?? new Client($authKey, $apiVersion, $host); } diff --git a/src/Glossary.php b/src/Glossary.php index b419ae6..d3e8b07 100644 --- a/src/Glossary.php +++ b/src/Glossary.php @@ -26,7 +26,7 @@ class Glossary * @param string $host * @param ClientInterface|null $client */ - public function __construct($authKey, $apiVersion = 2, $host = 'api.deepl.com', ClientInterface $client = null) + public function __construct($authKey, $apiVersion = 2, $host = 'api-free.deepl.com', ClientInterface $client = null) { $this->client = $client ?? new Client($authKey, $apiVersion, $host); } diff --git a/tests/integration/DeepLApiTest.php b/tests/integration/DeepLApiTest.php index 05fe863..fbda71e 100644 --- a/tests/integration/DeepLApiTest.php +++ b/tests/integration/DeepLApiTest.php @@ -48,7 +48,7 @@ public static function setUpBeforeClass(): void parent::setUpBeforeClass(); $authKey = getenv('DEEPL_AUTH_KEY'); - $apiHost = getenv('DEEPL_HOST') ?: 'api.deepl.com'; + $apiHost = getenv('DEEPL_HOST') ?: 'api-free.deepl.com'; $proxy = getenv('HTTP_PROXY'); $proxyCredentials = getenv('HTTP_PROXY_CREDENTIALS'); diff --git a/tests/integration/GlossaryTest.php b/tests/integration/GlossaryTest.php index aa6e13f..86b1329 100644 --- a/tests/integration/GlossaryTest.php +++ b/tests/integration/GlossaryTest.php @@ -30,7 +30,7 @@ public static function setUpBeforeClass(): void parent::setUpBeforeClass(); $authKey = getenv('DEEPL_AUTH_KEY'); - $apiHost = getenv('DEEPL_HOST') ?: 'api.deepl.com'; + $apiHost = getenv('DEEPL_HOST') ?: 'api-free.deepl.com'; if ($authKey === false) { self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.'); From cf59736baac0ae1661ae94a12c7e13fc0559484a Mon Sep 17 00:00:00 2001 From: vims Date: Fri, 29 Apr 2022 09:27:26 +0200 Subject: [PATCH 10/14] abandon package and recommend deeplcom/deepl-php --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index be3ed61..fd3678d 100644 --- a/composer.json +++ b/composer.json @@ -1,4 +1,5 @@ { + "abandoned": "deeplcom/deepl-php", "name": "babymarkt/deepl-php-lib", "type": "library", "description": "DeepL API Client Library supporting PHP >= 7.3 && PHP <= 8.1", From 835ffc357bd2c1a0de0cb939ff6d38d6e32bc114 Mon Sep 17 00:00:00 2001 From: vims Date: Fri, 29 Apr 2022 09:57:55 +0200 Subject: [PATCH 11/14] Fix some Tests. --- tests/integration/DeepLApiTest.php | 16 ++++++++++------ tests/unit/ClientTest.php | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/integration/DeepLApiTest.php b/tests/integration/DeepLApiTest.php index fbda71e..e3199e8 100644 --- a/tests/integration/DeepLApiTest.php +++ b/tests/integration/DeepLApiTest.php @@ -92,12 +92,14 @@ public function testTranslateSuccess() $deepl = new DeepL(self::$authKey, 2, self::$apiHost); - $germanText = 'Hallo Welt'; - $expectedText = 'Hello world'; + $germanText = 'Hallo Welt, dies ist ein deutscher Text.'; + $expectedText = 'Hello world, this is a German text.'; + $expectedLanguage = 'DE'; $translatedText = $deepl->translate($germanText); self::assertEquals($expectedText, $translatedText[0]['text']); + self::assertEquals($expectedLanguage, $translatedText[0]['detected_source_language']); } /** @@ -111,12 +113,14 @@ public function testTranslateV1Success() $deepl = new DeepL(self::$authKey, 1, self::$apiHost); - $germanText = 'Hallo Welt'; - $expectedText = 'Hello world'; + $germanText = 'Hallo Welt'; + $expectedText = 'Hallo Welt'; + $expectedLanguage = 'IT'; $translatedText = $deepl->translate($germanText); self::assertEquals($expectedText, $translatedText[0]['text']); + self::assertEquals($expectedLanguage, $translatedText[0]['detected_source_language']); } /** @@ -383,7 +387,7 @@ public function testTranslateWithHTML() $deepl = new DeepL(self::$authKey, 2, self::$apiHost); $textToTranslate = array( 'Hello WorldThis should stay the same', - 'Another Text
new line

this is a paragraph

' + 'Another Text
new line.

This is a paragraph

' ); $expectedArray = array( @@ -393,7 +397,7 @@ public function testTranslateWithHTML() ), array( 'detected_source_language' => "EN", - 'text' => "Eine weitere
neue Textzeile

, dies ist ein Absatz


", + 'text' => "Eine weitere
neue Textzeile.

Dies ist ein Absatz


", ), ); diff --git a/tests/unit/ClientTest.php b/tests/unit/ClientTest.php index 2d0a0e6..0ce35f4 100644 --- a/tests/unit/ClientTest.php +++ b/tests/unit/ClientTest.php @@ -203,7 +203,7 @@ public function testBuildBaseUrlHost() public function testBuildBaseUrl() { $authKey = '123456'; - $expectedUrl = 'https://api.deepl.com/v2/translate'; + $expectedUrl = 'https://api-free.deepl.com/v2/translate'; $testSubject = new Client($authKey); $result = $testSubject->buildBaseUrl(); From 776f82c958004867e2deafb51c5a5ea6ab43766f Mon Sep 17 00:00:00 2001 From: vims Date: Fri, 29 Apr 2022 14:40:45 +0200 Subject: [PATCH 12/14] updated CHANGELOG.md --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1940120..3e1c7a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,14 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [3.1.0] - 2022-29-04 +## [4.0.0] - 2022-**-05 ### Added +- marked Package as abandoned - PHP 8.1 compatibility - glossary_id to translate-method - ability to run Integration-Tests against custom host if needed (Free/Pro) ### Changed - migrated phpunit.xml.dist - fixed some Tests and general Maintenance such as Typos in README.md +- **Breaking Change!** standard DEEPL_HOST to free again +- **Breaking Change!** default source Langauge form DE to empty so DeepL will decide ### Removed ## [3.0.1] - 2021-07-09 From 4da8abb66766c099b8072b79f24c05f2d9ccd527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Fri, 6 May 2022 14:15:53 +0200 Subject: [PATCH 13/14] Client: PHP 8.1 compatibility. --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 18045df..0fef733 100644 --- a/src/Client.php +++ b/src/Client.php @@ -215,7 +215,7 @@ public function buildQuery($paramsArray) } } - $body = http_build_query($paramsArray, null, '&'); + $body = http_build_query($paramsArray, '', '&'); if (isset($textString)) { $body = $textString . '&' . $body; From 0e16a08f6ff24d021a7243552baf0850c04714d8 Mon Sep 17 00:00:00 2001 From: mgoniwiecha Date: Mon, 9 May 2022 19:32:34 +0200 Subject: [PATCH 14/14] Added blank line --- tests/integration/DeepLApiTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/integration/DeepLApiTest.php b/tests/integration/DeepLApiTest.php index e3199e8..166b5fe 100644 --- a/tests/integration/DeepLApiTest.php +++ b/tests/integration/DeepLApiTest.php @@ -28,6 +28,7 @@ class DeepLApiTest extends TestCase * @var string */ protected static $apiHost; + /** * Proxy URL * @var bool|string