Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
composer.lock
phpunit.xml

/.phpunit.result.cache
16 changes: 1 addition & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,7 @@ language: php

matrix:
include:
- php: 5.3
dist: precise
- php: 5.4
dist: precise
- php: 5.5
dist: precise
- php: 5.6
- php: 7.0
- php: 7.1
- php: 7.2
- php: 7.3
- php: 7.4snapshot
- php: nightly
allow_failures:
- php: nightly
- php: 8.0

env:
- COMPOSER_ALLOW_XDEBUG=0
Expand Down
73 changes: 70 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

Simple PHP Library for DeepL API. You can translate one or multiple text strings (up to 50) per request.

🇩🇪🇬🇧🇺🇸🇪🇸🇲🇽🇫🇷🇮🇹🇯🇵🇳🇱🇵🇱🇵🇹🇧🇷🇷🇺🇨🇳
🇩🇪🇦🇹🇨🇭🇬🇧🇺🇸🇪🇸🇲🇽🇫🇷🇮🇹🇯🇵🇳🇱🇵🇱🇵🇹🇧🇷🇷🇺🇨🇳🇬🇷🇩🇰🇨🇿🇪🇪🇫🇮🇭🇺🇱🇹🇱🇻🇷🇴🇷🇸🇸🇰🇸🇪

[Official DeepL API][link-deepl]

Expand All @@ -32,6 +32,12 @@ $authKey = '<AUTH KEY>';
$deepl = new DeepL($authKey);
```

Use the DeepL API Pro:
```php
$authKey = '<AUTH KEY>';
$deepl = new DeepL($authKey,2,'api.deepl.com');
```

### Translate
Translate one Text:

Expand Down Expand Up @@ -99,12 +105,73 @@ foreach ($targetLanguagesArray as $targetLanguage) {
}
```
### Monitoring usage
You can now check ow much you translate, as well as the limit:
You can now check how much you translate, as well as the limit:
```php
$usageArray = $deepl->usage();

echo 'You have used '.$usageArray['character_count'].' of '.$usageArray['character_limit'].' in the current billing period.'.PHP_EOL;

```

### Glossary
Create a glossary
```php
$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 |

Delete a glossary
```php
$glossary = $deepl->deleteGlossary($glossaryId);
```

| param | Description |
|---------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| $glossaryId | Glossary uuid (set by DeepL when glossary is created)

List glossaries
```php
$glossaries = $deepl->listGlossaries();
foreach ($glossaries as $glossary) {
var_dump($glossary);
}
```

Get glossary meta information: creation date, is glossary ready to use ...
```php
$glossaryInformation = $deepl->glossaryInformation($glossaryId);
var_dump($glossaryInformation);
```

| param | Description |
|---------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| $glossaryId | Glossary uuid (set by DeepL when glossary is created)

Get glossary entries
```php
$entries = $deepl->glossaryEntries($glossaryId);
foreach ($entries as $sourceLangText => $targetLangText) {
echo $sourceLangText .' > '.$targetLangText;
}
```

| 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
```php
$deepl->setTimeout(10); //give up after 10 seconds
$deepl->setProxy('http://corporate-proxy.com:3128');
$deepl->setProxyCredentials('username:password');

```
## Testing

Expand Down Expand Up @@ -149,7 +216,7 @@ The MIT License (MIT). Please see [License File](LICENSE.md) for more informatio
[ico-downloads]: https://img.shields.io/packagist/dt/babymarkt/deepl-php-lib.svg?style=flat-square

[link-packagist]: https://packagist.org/packages/babymarkt/deepl-php-lib
[link-travis]: https://travis-ci.org/Baby-Markt/deepl-php-lib
[link-travis]: https://travis-ci.com/Baby-Markt/deepl-php-lib
[link-scrutinizer]: https://scrutinizer-ci.com/g/Baby-Markt/deepl-php-lib/code-structure
[link-code-quality]: https://scrutinizer-ci.com/g/Baby-Markt/deepl-php-lib
[link-downloads]: https://packagist.org/packages/babymarkt/deepl-php-lib
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "babymarkt/deepl-php-lib",
"type": "library",
"description": "DeepL API Client Library supporting PHP >= 5.3 && PHP < 8.0",
"description": "DeepL API Client Library supporting PHP >= 8.0",
"keywords": [
"babymarkt",
"deepl",
Expand All @@ -19,14 +19,14 @@
}
],
"require": {
"php": ">=5.3 <8.0",
"php": ">=8.0",
"ext-json": "*",
"ext-curl": "*"
},
"require-dev": {
"phpmd/phpmd": "2.4.*",
"phpunit/phpunit": "^4.8",
"squizlabs/php_codesniffer": "^2.9"
"phpmd/phpmd": "^2.9",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.5"
},
"autoload": {
"psr-4": {
Expand Down
Loading