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

Commit acfcc58

Browse files
committed
add formality parameter
(cherry picked from commit 0740de4)
1 parent d70e3a3 commit acfcc58

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/DeepL.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ class DeepL
4949
*/
5050
const API_URL_IGNORE_TAGS = 'ignore_tags=%s';
5151

52+
/**
53+
* API URL: Parameter formality
54+
*/
55+
const API_URL_FORMALITY = 'formality=%s';
56+
5257
/**
5358
* DeepL HTTP error codes
5459
*
@@ -148,6 +153,7 @@ public function __destruct()
148153
* @param string $destinationLanguage
149154
* @param array $tagHandling
150155
* @param array $ignoreTags
156+
* @param string $formality
151157
*
152158
* @return string|string[]
153159
*
@@ -158,13 +164,14 @@ public function translate(
158164
$sourceLanguage = 'de',
159165
$destinationLanguage = 'en',
160166
array $tagHandling = array(),
161-
array $ignoreTags = array()
167+
array $ignoreTags = array(),
168+
$formality = "default"
162169
) {
163170
// make sure we only accept supported languages
164171
$this->checkLanguages($sourceLanguage, $destinationLanguage);
165172

166173
// build the DeepL API request url
167-
$url = $this->buildUrl($sourceLanguage, $destinationLanguage, $tagHandling, $ignoreTags);
174+
$url = $this->buildUrl($sourceLanguage, $destinationLanguage, $tagHandling, $ignoreTags, $formality);
168175
$body = $this->buildBody($text);
169176

170177
// request the DeepL API
@@ -218,14 +225,16 @@ protected function checkLanguages($sourceLanguage, $destinationLanguage)
218225
* @param string $destinationLanguage
219226
* @param array $tagHandling
220227
* @param array $ignoreTags
228+
* @param string $formality
221229
*
222230
* @return string
223231
*/
224232
protected function buildUrl(
225233
$sourceLanguage,
226234
$destinationLanguage,
227235
array $tagHandling = array(),
228-
array $ignoreTags = array()
236+
array $ignoreTags = array(),
237+
$formality = "default"
229238
) {
230239
// select correct api url
231240
switch ($this->apiVersion) {
@@ -251,6 +260,10 @@ protected function buildUrl(
251260
$url .= '&' . sprintf(DeepL::API_URL_IGNORE_TAGS, implode(',', $ignoreTags));
252261
}
253262

263+
if(!empty($formality)) {
264+
$url .= '&' . sprintf(DeepL::API_URL_FORMALITY, $formality);
265+
}
266+
254267
return $url;
255268
}
256269

0 commit comments

Comments
 (0)