Skip to content

Commit 71cc3f4

Browse files
feat: Add tag_handling_version parameter to translate_text
1 parent b0b941a commit 71cc3f4

File tree

5 files changed

+53
-0
lines changed

5 files changed

+53
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Added
9+
- Added `setTagHandlingVersion()` method to `TextTranslationOptions` to specify which version of the tag handling algorithm to use. Options are `v1` and `v2`.
810

911
## [1.13.0] - 2025-12-03
1012
### Added

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ a `TextTranslationOptions`, with the following setters:
187187
cost of translation quality.
188188
- `setTagHandling()`: type of tags to parse before translation, options are
189189
`"html"` and `"xml"`.
190+
- `setTagHandlingVersion()`: specifies which version of the tag handling algorithm to use. Options are `"v1"` and `"v2"`.
190191

191192
The following options are only used if `setTagHandling()` is set to `'xml'`:
192193

deepl-java/src/main/java/com/deepl/api/TextTranslationOptions.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class TextTranslationOptions extends BaseRequestOptions {
2121
private boolean preserveFormatting = false;
2222
private String context;
2323
private String tagHandling;
24+
private String tagHandlingVersion;
2425
private String modelType;
2526
private boolean outlineDetection = true;
2627
private Iterable<String> ignoreTags;
@@ -126,6 +127,15 @@ public TextTranslationOptions setTagHandling(String tagHandling) {
126127
return this;
127128
}
128129

130+
/**
131+
* Sets the version of tag handling algorithm to use. By default, this value is <code>null</code>
132+
* and the API default is used.
133+
*/
134+
public TextTranslationOptions setTagHandlingVersion(String tagHandlingVersion) {
135+
this.tagHandlingVersion = tagHandlingVersion;
136+
return this;
137+
}
138+
129139
/**
130140
* Set the type of model to use for a text translation. Currently supported values: <code>
131141
* "quality_optimized"</code> use a translation model that maximizes translation quality, at the
@@ -225,6 +235,11 @@ public String getTagHandling() {
225235
return tagHandling;
226236
}
227237

238+
/** Gets the current tag handling version. */
239+
public String getTagHandlingVersion() {
240+
return tagHandlingVersion;
241+
}
242+
228243
/** Gets the current outline detection setting. */
229244
public boolean isOutlineDetection() {
230245
return outlineDetection;

deepl-java/src/main/java/com/deepl/api/Translator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,9 @@ private static ArrayList<KeyValuePair<String, String>> createHttpParams(
833833
if (options.getTagHandling() != null) {
834834
params.add(new KeyValuePair<>("tag_handling", options.getTagHandling()));
835835
}
836+
if (options.getTagHandlingVersion() != null) {
837+
params.add(new KeyValuePair<>("tag_handling_version", options.getTagHandlingVersion()));
838+
}
836839
if (!options.isOutlineDetection()) {
837840
params.add(new KeyValuePair<>("outline_detection", "0"));
838841
}

deepl-java/src/test/java/com/deepl/api/TranslateTextTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,38 @@ void testTagHandlingHTML() throws DeepLException, InterruptedException {
299299
}
300300
}
301301

302+
@Test
303+
void testTagHandlingVersionV1() throws DeepLException, InterruptedException {
304+
Translator translator = createTranslator();
305+
String text = "<p>Hello world</p>";
306+
307+
TextResult result =
308+
translator.translateText(
309+
text,
310+
null,
311+
"de",
312+
new TextTranslationOptions().setTagHandling("html").setTagHandlingVersion("v1"));
313+
Assertions.assertNotNull(result);
314+
Assertions.assertNotNull(result.getText());
315+
Assertions.assertFalse(result.getText().isEmpty());
316+
}
317+
318+
@Test
319+
void testTagHandlingVersionV2() throws DeepLException, InterruptedException {
320+
Translator translator = createTranslator();
321+
String text = "<p>Hello world</p>";
322+
323+
TextResult result =
324+
translator.translateText(
325+
text,
326+
null,
327+
"de",
328+
new TextTranslationOptions().setTagHandling("html").setTagHandlingVersion("v2"));
329+
Assertions.assertNotNull(result);
330+
Assertions.assertNotNull(result.getText());
331+
Assertions.assertFalse(result.getText().isEmpty());
332+
}
333+
302334
@Test
303335
void testEmptyText() {
304336
Translator translator = createTranslator();

0 commit comments

Comments
 (0)