Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 3cf120c

Browse files
committed
Add tag_handling optional param
1 parent 80a0fca commit 3cf120c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/DeepL.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ class DeepL
3434
*/
3535
const API_URL_DESTINATION_LANG = 'target_lang=%s';
3636

37+
/**
38+
* API v1 URL: Parameter tag_handling
39+
*/
40+
const API_URL_TAG_HANDLING = 'tag_handling=%s';
41+
3742
/**
3843
* DeepL HTTP error codes
3944
*
@@ -120,18 +125,19 @@ public function __destruct()
120125
* @param $text string|string[]
121126
* @param $sourceLanguage string
122127
* @param $destinationLanguage string
128+
* @param $tagHandling array
123129
*
124130
* @return string|string[]
125131
*
126132
* @throws DeepLException
127133
*/
128-
public function translate($text, $sourceLanguage = 'de', $destinationLanguage = 'en')
134+
public function translate($text, $sourceLanguage = 'de', $destinationLanguage = 'en', array $tagHandling = [])
129135
{
130136
// make sure we only accept supported languages
131137
$this->checkLanguages($sourceLanguage, $destinationLanguage);
132138

133139
// build the DeepL API request url
134-
$url = $this->buildUrl($sourceLanguage, $destinationLanguage);
140+
$url = $this->buildUrl($sourceLanguage, $destinationLanguage, $tagHandling);
135141
$body = $this->buildBody($text);
136142

137143
// request the DeepL API
@@ -185,12 +191,15 @@ protected function checkLanguages($sourceLanguage, $destinationLanguage)
185191
*
186192
* @return string
187193
*/
188-
protected function buildUrl($sourceLanguage, $destinationLanguage)
194+
protected function buildUrl($sourceLanguage, $destinationLanguage, $tagHandling)
189195
{
190196
$url = DeepL::API_URL . '?' . sprintf(DeepL::API_URL_AUTH_KEY, $this->authKey);
191197

192198
$url .= '&' . sprintf(DeepL::API_URL_SOURCE_LANG, strtolower($sourceLanguage));
193199
$url .= '&' . sprintf(DeepL::API_URL_DESTINATION_LANG, strtolower($destinationLanguage));
200+
if (!empty($tagHandling)) {
201+
$url .= '&' . sprintf(DeepL::API_URL_TAG_HANDLING, implode(',', $tagHandling));
202+
}
194203

195204
return $url;
196205
}

0 commit comments

Comments
 (0)