-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from prugala/feature/deepl-formality-and-changes
Allow setting formality parameter for DeepL providers + new provider for free version of DeepL
- Loading branch information
Showing
12 changed files
with
137 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name: Analysis | ||
on: [push] | ||
on: [push, pull_request] | ||
|
||
jobs: | ||
php-cs-fixer: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name: Tests | ||
on: [push] | ||
on: [push, pull_request] | ||
|
||
jobs: | ||
build-test: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/DivanteTranslationBundle/Provider/DeeplFreeProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
/** | ||
* @author Piotr Rugała <piotr@isedo.pl> | ||
* @copyright Copyright (c) 2021 Divante Ltd. (https://divante.co) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DivanteTranslationBundle\Provider; | ||
|
||
class DeeplFreeProvider extends DeeplProvider | ||
{ | ||
protected string $url = 'https://api-free.deepl.com/'; | ||
|
||
public function getName(): string | ||
{ | ||
return 'deepl_free'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/DivanteTranslationBundle/Provider/FormalityProviderInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
/** | ||
* @author Piotr Rugała <piotr@isedo.pl> | ||
* @copyright Copyright (c) 2021 Divante Ltd. (https://divante.co) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DivanteTranslationBundle\Provider; | ||
|
||
interface FormalityProviderInterface | ||
{ | ||
public function setFormality(?string $formality): self; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
tests/DivanteTranslationBundle/Provider/DeeplFreeProviderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* @author Piotr Rugała <piotr@isedo.pl> | ||
* @copyright Copyright (c) 2021 Divante Ltd. (https://divante.co) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\DivanteTranslationBundle\Provider; | ||
|
||
use DivanteTranslationBundle\Provider\DeeplFreeProvider; | ||
use DivanteTranslationBundle\Provider\ProviderInterface; | ||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Handler\MockHandler; | ||
use GuzzleHttp\HandlerStack; | ||
use GuzzleHttp\Psr7\Response; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class DeeplFreeProviderTest extends TestCase | ||
{ | ||
public function testTranslate(): void | ||
{ | ||
$response = [ | ||
'translations' => [ | ||
[ | ||
'text' => 'test' | ||
], | ||
], | ||
]; | ||
|
||
$this->assertSame('test', $this->createProvider($response)->translate('test', 'en')); | ||
} | ||
|
||
private function createProvider(array $response): ProviderInterface | ||
{ | ||
$mock = new MockHandler([ | ||
new Response(200, [], json_encode($response)), | ||
]); | ||
$handlerStack = HandlerStack::create($mock); | ||
$client = new Client(['handler' => $handlerStack]); | ||
$provider = $this->getMockBuilder(DeeplFreeProvider::class) | ||
->onlyMethods(['getHttpClient']) | ||
->getMock(); | ||
$provider->method('getHttpClient')->willReturn($client); | ||
$provider->setApiKey('test'); | ||
$provider->setFormality('more'); | ||
|
||
return $provider; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters