@@ -34,6 +34,11 @@ class DeepL
34
34
*/
35
35
const API_URL_DESTINATION_LANG = 'target_lang=%s ' ;
36
36
37
+ /**
38
+ * API v1 URL: Parameter tag_handling
39
+ */
40
+ const API_URL_TAG_HANDLING = 'tag_handling=%s ' ;
41
+
37
42
/**
38
43
* DeepL HTTP error codes
39
44
*
@@ -120,18 +125,19 @@ public function __destruct()
120
125
* @param $text string|string[]
121
126
* @param $sourceLanguage string
122
127
* @param $destinationLanguage string
128
+ * @param $tagHandling array
123
129
*
124
130
* @return string|string[]
125
131
*
126
132
* @throws DeepLException
127
133
*/
128
- public function translate ($ text , $ sourceLanguage = 'de ' , $ destinationLanguage = 'en ' )
134
+ public function translate ($ text , $ sourceLanguage = 'de ' , $ destinationLanguage = 'en ' , array $ tagHandling = [] )
129
135
{
130
136
// make sure we only accept supported languages
131
137
$ this ->checkLanguages ($ sourceLanguage , $ destinationLanguage );
132
138
133
139
// build the DeepL API request url
134
- $ url = $ this ->buildUrl ($ sourceLanguage , $ destinationLanguage );
140
+ $ url = $ this ->buildUrl ($ sourceLanguage , $ destinationLanguage, $ tagHandling );
135
141
$ body = $ this ->buildBody ($ text );
136
142
137
143
// request the DeepL API
@@ -185,12 +191,15 @@ protected function checkLanguages($sourceLanguage, $destinationLanguage)
185
191
*
186
192
* @return string
187
193
*/
188
- protected function buildUrl ($ sourceLanguage , $ destinationLanguage )
194
+ protected function buildUrl ($ sourceLanguage , $ destinationLanguage, $ tagHandling )
189
195
{
190
196
$ url = DeepL::API_URL . '? ' . sprintf (DeepL::API_URL_AUTH_KEY , $ this ->authKey );
191
197
192
198
$ url .= '& ' . sprintf (DeepL::API_URL_SOURCE_LANG , strtolower ($ sourceLanguage ));
193
199
$ url .= '& ' . sprintf (DeepL::API_URL_DESTINATION_LANG , strtolower ($ destinationLanguage ));
200
+ if (!empty ($ tagHandling )) {
201
+ $ url .= '& ' . sprintf (DeepL::API_URL_TAG_HANDLING , implode (', ' , $ tagHandling ));
202
+ }
194
203
195
204
return $ url ;
196
205
}
0 commit comments