Skip to content

Commit

Permalink
Merge pull request #7 from didoda/refactor/rename-translator
Browse files Browse the repository at this point in the history
Rename class to Translator
  • Loading branch information
didoda authored Nov 6, 2023
2 parents 9712510 + e219edb commit 1e56885
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ This plugin uses [DeepL Translator](https://www.deepl.com/translator) to transla

Usage example:
```php
use BEdita\I18n\Translator\DeepLTranslator;
use BEdita\I18n\Deepl\Core\Translator;

$translator = new DeepLTranslator();
$translator = new Translator();
$translator->setup(['auth_key' => 'your-auth-key']);
$translation = $translator->translate(['Hello world!'], 'en', 'it');
```
14 changes: 8 additions & 6 deletions src/Core/DeepLTranslator.php → src/Core/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,30 @@

use BEdita\I18n\Core\TranslatorInterface;
use Cake\Utility\Hash;
use DeepL\Translator;
use DeepL\Translator as DeeplTranslator;

/**
* DeepL translator class that uses DeepL.
* Translator class that uses DeepL.
*
* This class uses the DeepL API to translate texts.
* Pass a valid 'auth_key' to the options array to use this engine.
* Example:
* ```
* $translator = new DeepLTranslator();
* use BEdita\I18n\Deepl\Core\Translator;
* [...]
* $translator = new Translator();
* $translator->setup(['auth_key' => 'your-auth-key']);
* $translation = $translator->translate(['Hello world!'], 'en', 'it');
* ```
*/
class DeepLTranslator implements TranslatorInterface
class Translator implements TranslatorInterface
{
/**
* The DeepL API client.
*
* @var \DeepL\Translator
*/
protected Translator $deeplClient;
protected DeeplTranslator $deeplClient;

/**
* The engine options.
Expand All @@ -56,7 +58,7 @@ public function setup(array $options = []): void
{
$this->options = $options;
$authKey = $this->options['auth_key'] ?? '';
$this->deeplClient = new Translator($authKey);
$this->deeplClient = new DeeplTranslator($authKey);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
*/
namespace BEdita\I18n\Deepl\Test\Core;

use BEdita\I18n\Deepl\Core\DeepLTranslator;
use BEdita\I18n\Deepl\Core\Translator;
use Cake\TestSuite\TestCase;
use DeepL\TextResult;
use DeepL\Translator;
use DeepL\Translator as DeeplTranslator;

/**
* {@see \BEdita\I18n\Deepl\Core\DeepLTranslator} Test Case
* {@see \BEdita\I18n\Deepl\Core\Translator} Test Case
*
* @covers \BEdita\I18n\Deepl\Core\DeepLTranslator
* @covers \BEdita\I18n\Deepl\Core\Translator
*/
class DeepLTranslatorTest extends TestCase
class TranslatorTest extends TestCase
{
/**
* Test setup.
Expand All @@ -34,8 +34,8 @@ class DeepLTranslatorTest extends TestCase
*/
public function testSetup(): void
{
$translator = new class extends DeepLTranslator {
public function getDeepLClient(): Translator
$translator = new class extends Translator {
public function getDeepLClient(): DeeplTranslator
{
return $this->deeplClient;
}
Expand All @@ -52,10 +52,10 @@ public function getDeepLClient(): Translator
*/
public function testTranslate(): void
{
$translator = new class extends DeepLTranslator {
$translator = new class extends Translator {
public function setup(array $options = []): void
{
$this->deeplClient = new class ('fake-auth-key') extends Translator
$this->deeplClient = new class ('fake-auth-key') extends DeeplTranslator
{
/**
* @inheritDoc
Expand Down

0 comments on commit 1e56885

Please sign in to comment.