@@ -34,6 +34,17 @@ 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
+
42
+ /**
43
+ * API v1 URL: Parameter ignore_tags
44
+ */
45
+ const API_URL_IGNORE_TAGS = 'ignore_tags=%s ' ;
46
+
47
+
37
48
/**
38
49
* DeepL HTTP error codes
39
50
*
@@ -91,6 +102,13 @@ class DeepL
91
102
*/
92
103
protected $ curl ;
93
104
105
+ /**
106
+ * DeepL ingored tags
107
+ *
108
+ * @var array
109
+ */
110
+ protected $ ignoreTags = array ();
111
+
94
112
/**
95
113
* DeepL constructor
96
114
*
@@ -120,18 +138,19 @@ public function __destruct()
120
138
* @param $text string|string[]
121
139
* @param $sourceLanguage string
122
140
* @param $destinationLanguage string
141
+ * @param $tagHandling array
123
142
*
124
143
* @return string|string[]
125
144
*
126
145
* @throws DeepLException
127
146
*/
128
- public function translate ($ text , $ sourceLanguage = 'de ' , $ destinationLanguage = 'en ' )
147
+ public function translate ($ text , $ sourceLanguage = 'de ' , $ destinationLanguage = 'en ' , array $ tagHandling = array () )
129
148
{
130
149
// make sure we only accept supported languages
131
150
$ this ->checkLanguages ($ sourceLanguage , $ destinationLanguage );
132
151
133
152
// build the DeepL API request url
134
- $ url = $ this ->buildUrl ($ sourceLanguage , $ destinationLanguage );
153
+ $ url = $ this ->buildUrl ($ sourceLanguage , $ destinationLanguage, $ tagHandling );
135
154
$ body = $ this ->buildBody ($ text );
136
155
137
156
// request the DeepL API
@@ -185,12 +204,20 @@ protected function checkLanguages($sourceLanguage, $destinationLanguage)
185
204
*
186
205
* @return string
187
206
*/
188
- protected function buildUrl ($ sourceLanguage , $ destinationLanguage )
207
+ protected function buildUrl ($ sourceLanguage , $ destinationLanguage, $ tagHandling = array () )
189
208
{
190
209
$ url = DeepL::API_URL . '? ' . sprintf (DeepL::API_URL_AUTH_KEY , $ this ->authKey );
191
210
192
211
$ url .= '& ' . sprintf (DeepL::API_URL_SOURCE_LANG , strtolower ($ sourceLanguage ));
193
212
$ url .= '& ' . sprintf (DeepL::API_URL_DESTINATION_LANG , strtolower ($ destinationLanguage ));
213
+ if (!empty ($ tagHandling )) {
214
+ $ url .= '& ' . sprintf (DeepL::API_URL_TAG_HANDLING , implode (', ' , $ tagHandling ));
215
+ }
216
+ if (!empty ($ this ->ignoreTags )) {
217
+ $ url .= '& ' . sprintf (DeepL::API_URL_IGNORE_TAGS , implode (', ' , $ this ->ignoreTags ));
218
+ }
219
+
220
+
194
221
195
222
return $ url ;
196
223
}
@@ -259,4 +286,9 @@ protected function request($url, $body)
259
286
260
287
return $ translationsArray ;
261
288
}
289
+
290
+ public function setIgnoreTags (array $ ignoreTags )
291
+ {
292
+ $ this ->ignoreTags = $ ignoreTags ;
293
+ }
262
294
}
0 commit comments