-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jimmy ESCRICH <[email protected]>
- Loading branch information
Showing
38 changed files
with
858 additions
and
33 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
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,98 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
||
use Scn\DeeplApiConnector\DeeplClientFactory; | ||
use Scn\DeeplApiConnector\Enum\GlossarySubmissionEntryFormatEnum; | ||
use Scn\DeeplApiConnector\Model\GlossariesListInterface; | ||
use Scn\DeeplApiConnector\Model\GlossaryEntries; | ||
use Scn\DeeplApiConnector\Model\GlossaryIdSubmission; | ||
use Scn\DeeplApiConnector\Model\GlossaryInterface; | ||
use Scn\DeeplApiConnector\Model\GlossarySubmission; | ||
use Scn\DeeplApiConnector\Model\GlossariesSupportedLanguagesPairsInterface; | ||
use Scn\DeeplApiConnector\Model\TranslationConfig; | ||
|
||
$apiKey = 'your-api-key'; | ||
|
||
$deepl = DeeplClientFactory::create($apiKey); | ||
|
||
/** @var GlossariesSupportedLanguagesPairsInterface $result */ | ||
$result = $deepl->getGlossariesSupportedLanguagesPairs(); | ||
/** | ||
* List all available pairs | ||
*/ | ||
var_dump($result->getList()); | ||
|
||
/** @var GlossariesListInterface $result */ | ||
$result = $deepl->getGlossariesList(); | ||
/** | ||
* List all glossaries | ||
*/ | ||
var_dump($result->getList()); | ||
|
||
$input = (new GlossarySubmission()) | ||
->setName('en => nl') | ||
->setSourceLang('en') | ||
->setTargetLang('nl') | ||
->setEntries("Hello\tDag\nDog\tHond"); | ||
|
||
// NB.: Note that entries can be a tsv or csv. Related to the documentation : https://www.deepl.com/fr/docs-api/glossaries/formats | ||
// To use CSV, this is the example : | ||
|
||
$input->setEntriesFormat(GlossarySubmissionEntryFormatEnum::FORMAT_CSV) | ||
->setEntries("Hello,Dag\nDog,Hond"); | ||
/** @var GlossaryInterface $glossary */ | ||
$glossary = $deepl->createGlossary($input); | ||
/** | ||
* Get created glossary | ||
*/ | ||
var_dump($glossary->getDetails()); | ||
|
||
$input = (new GlossaryIdSubmission()) | ||
->setId($glossary->getDetails()['glossary_id']); | ||
/** @var GlossaryInterface $result */ | ||
$result = $deepl->retrieveGlossary($input); | ||
/** | ||
* Get glossary details | ||
*/ | ||
var_dump($result->getDetails()); | ||
|
||
/** @var GlossaryEntries $result */ | ||
$result = $deepl->retrieveGlossaryEntries($input); | ||
/** | ||
* Get glossary entries array | ||
*/ | ||
var_dump($result->getList()); | ||
/** | ||
* Get glossary entries real result | ||
*/ | ||
var_dump($result->getResult()); | ||
|
||
$result = $deepl->deleteGlossary($input); | ||
/** | ||
* True if glossary successfully deleted | ||
*/ | ||
var_dump($result); | ||
|
||
/** | ||
* Now, whe can get the glossary from the source and target lang and use it in the TranslationConfig | ||
*/ | ||
$source = 'en'; | ||
$target = 'nl'; | ||
/** @var GlossariesListInterface $glossaries */ | ||
$glossaries = $deepl->getGlossariesList(); | ||
$glossary = current(array_filter( | ||
$glossaries->getList(), | ||
fn (array $e) => $e['source_lang'] === $source && $e['target_lang'] === $target | ||
)); | ||
|
||
$translationConfig = new TranslationConfig( | ||
'Hello World', | ||
$target, | ||
$source, | ||
glossaryId: $glossary !== false ? $glossary['glossary_id'] : '' | ||
); | ||
$translationObj = $deepl->getTranslation($translationConfig); | ||
var_dump($translationObj); |
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
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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Scn\DeeplApiConnector\Enum; | ||
|
||
final class GlossarySubmissionEntryFormatEnum | ||
{ | ||
public const FORMAT_TSV = 'tsv'; | ||
public const FORMAT_CSV = 'csv'; | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace Scn\DeeplApiConnector\Handler; | ||
|
||
abstract class AbstractDeeplHandler implements DeeplRequestHandlerInterface | ||
{ | ||
public function getAuthHeader(): ?string | ||
{ | ||
return null; | ||
} | ||
|
||
public function getAcceptHeader(): ?string | ||
{ | ||
return null; | ||
} | ||
} |
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
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
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
Oops, something went wrong.