@@ -49,6 +49,11 @@ class DeepL
49
49
*/
50
50
const API_URL_IGNORE_TAGS = 'ignore_tags=%s ' ;
51
51
52
+ /**
53
+ * API URL: Parameter formality
54
+ */
55
+ const API_URL_FORMALITY = 'formality=%s ' ;
56
+
52
57
/**
53
58
* DeepL HTTP error codes
54
59
*
@@ -148,6 +153,7 @@ public function __destruct()
148
153
* @param string $destinationLanguage
149
154
* @param array $tagHandling
150
155
* @param array $ignoreTags
156
+ * @param string $formality
151
157
*
152
158
* @return string|string[]
153
159
*
@@ -158,13 +164,14 @@ public function translate(
158
164
$ sourceLanguage = 'de ' ,
159
165
$ destinationLanguage = 'en ' ,
160
166
array $ tagHandling = array (),
161
- array $ ignoreTags = array ()
167
+ array $ ignoreTags = array (),
168
+ $ formality = "default "
162
169
) {
163
170
// make sure we only accept supported languages
164
171
$ this ->checkLanguages ($ sourceLanguage , $ destinationLanguage );
165
172
166
173
// build the DeepL API request url
167
- $ url = $ this ->buildUrl ($ sourceLanguage , $ destinationLanguage , $ tagHandling , $ ignoreTags );
174
+ $ url = $ this ->buildUrl ($ sourceLanguage , $ destinationLanguage , $ tagHandling , $ ignoreTags, $ formality );
168
175
$ body = $ this ->buildBody ($ text );
169
176
170
177
// request the DeepL API
@@ -218,14 +225,16 @@ protected function checkLanguages($sourceLanguage, $destinationLanguage)
218
225
* @param string $destinationLanguage
219
226
* @param array $tagHandling
220
227
* @param array $ignoreTags
228
+ * @param string $formality
221
229
*
222
230
* @return string
223
231
*/
224
232
protected function buildUrl (
225
233
$ sourceLanguage ,
226
234
$ destinationLanguage ,
227
235
array $ tagHandling = array (),
228
- array $ ignoreTags = array ()
236
+ array $ ignoreTags = array (),
237
+ $ formality = "default "
229
238
) {
230
239
// select correct api url
231
240
switch ($ this ->apiVersion ) {
@@ -251,6 +260,10 @@ protected function buildUrl(
251
260
$ url .= '& ' . sprintf (DeepL::API_URL_IGNORE_TAGS , implode (', ' , $ ignoreTags ));
252
261
}
253
262
263
+ if (!empty ($ formality )) {
264
+ $ url .= '& ' . sprintf (DeepL::API_URL_FORMALITY , $ formality );
265
+ }
266
+
254
267
return $ url ;
255
268
}
256
269
0 commit comments