Skip to content

Commit 6d41ac2

Browse files
hive-botclaude
andcommitted
feat: add enable_watermark option for document translation
Add DocumentTranslationOptions.setEnableWatermark() and getEnableWatermark(). When set, enable_watermark is sent as true/false on document upload; when unset, nothing is sent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 60d596d commit 6d41ac2

5 files changed

Lines changed: 89 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88
### Added
9+
- Added `DocumentTranslationOptions.setEnableWatermark()` to add a
10+
"Translated by DeepL" watermark to translated `docx` and `pdf` documents.
11+
By default the option is not sent.
912
- Added `DocumentTranslationOptions.setOutputFormat()` to request the file
1013
format of the translated document, for example `docx`. By default the
1114
translated document has the same format as the input document.

‎README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ arguments, `translateDocument()` accepts an optional
343343
- `setOutputFormat()`: the file format of the translated document, as a file
344344
extension, for example `docx`. By default the translated document has the
345345
same format as the input document.
346+
- `setEnableWatermark()`: set to `true` to add a "Translated by DeepL"
347+
watermark to the translated document. Only supported for `docx` and `pdf`
348+
output; for other output formats the API ignores it. By default the option
349+
is not sent and no watermark is added.
346350

347351
### Glossaries
348352

‎deepl-java/src/main/java/com/deepl/api/DocumentTranslationOptions.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.ArrayList;
77
import java.util.Arrays;
88
import java.util.List;
9+
import org.jetbrains.annotations.Nullable;
910

1011
/**
1112
* Options to control document translation behaviour. These options may be provided to {@link
@@ -25,6 +26,7 @@ public class DocumentTranslationOptions extends BaseRequestOptions {
2526
private String translationMemoryId;
2627
private Integer translationMemoryThreshold;
2728
private String outputFormat;
29+
private @Nullable Boolean enableWatermark;
2830

2931
/**
3032
* Sets whether translations should lean toward formal or informal language. This option is only
@@ -171,6 +173,17 @@ public DocumentTranslationOptions setOutputFormat(String outputFormat) {
171173
return this;
172174
}
173175

176+
/**
177+
* Sets whether a "Translated by DeepL" watermark is added to the translated document. The API
178+
* supports watermarks only for <code>docx</code> and <code>pdf</code> output and ignores this
179+
* option for other output formats. By default, this value is <code>null</code> and the option is
180+
* not sent, so the API default (no watermark) applies.
181+
*/
182+
public DocumentTranslationOptions setEnableWatermark(@Nullable Boolean enableWatermark) {
183+
this.enableWatermark = enableWatermark;
184+
return this;
185+
}
186+
174187
/** Gets the current formality setting. */
175188
public Formality getFormality() {
176189
return formality;
@@ -205,4 +218,9 @@ public Integer getTranslationMemoryThreshold() {
205218
public String getOutputFormat() {
206219
return outputFormat;
207220
}
221+
222+
/** Gets the current watermark setting, or <code>null</code> if it is not set. */
223+
public @Nullable Boolean getEnableWatermark() {
224+
return enableWatermark;
225+
}
208226
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,10 @@ protected static ArrayList<KeyValuePair<String, String>> createHttpParams(
912912
if (options.getOutputFormat() != null) {
913913
params.add(new KeyValuePair<>("output_format", options.getOutputFormat()));
914914
}
915+
if (options.getEnableWatermark() != null) {
916+
// The API ignores "1" here; only "true" enables the watermark.
917+
params.add(new KeyValuePair<>("enable_watermark", options.getEnableWatermark().toString()));
918+
}
915919
}
916920

917921
addExtraBodyParameters(params, options != null ? options.getExtraBodyParameters() : null);

‎deepl-java/src/offlineTest/java/com/deepl/api/TranslateDocumentTest.java‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,49 @@ void sendsAllDocumentOptionsInOrder() throws Exception {
159159
"output_format");
160160
}
161161

162+
@Test
163+
void sendsEnableWatermarkWithOutputFormat() throws Exception {
164+
File input = writeInput("example.txt", "a");
165+
expectUpload(
166+
"/v2/document",
167+
"example.txt",
168+
"a".getBytes(StandardCharsets.UTF_8),
169+
fields("target_lang", "de", "output_format", "docx", "enable_watermark", "true"));
170+
client.translateDocumentUpload(
171+
input,
172+
null,
173+
"de",
174+
new DocumentTranslationOptions().setOutputFormat("docx").setEnableWatermark(true));
175+
assertPartNames("/v2/document", "file", "target_lang", "output_format", "enable_watermark");
176+
}
177+
178+
@Test
179+
void sendsEnableWatermarkFalseWhenExplicitlyDisabled() throws Exception {
180+
File input = writeInput("example.txt", "a");
181+
expectUpload(
182+
"/v2/document",
183+
"example.txt",
184+
"a".getBytes(StandardCharsets.UTF_8),
185+
fields("target_lang", "de", "enable_watermark", "false"));
186+
client.translateDocumentUpload(
187+
input, null, "de", new DocumentTranslationOptions().setEnableWatermark(false));
188+
assertPartNames("/v2/document", "file", "target_lang", "enable_watermark");
189+
}
190+
191+
@Test
192+
void omitsEnableWatermarkWhenUnset() throws Exception {
193+
File input = writeInput("example.txt", "a");
194+
DocumentTranslationOptions options = new DocumentTranslationOptions().setOutputFormat("docx");
195+
assertNull(options.getEnableWatermark());
196+
expectUpload(
197+
"/v2/document",
198+
"example.txt",
199+
"a".getBytes(StandardCharsets.UTF_8),
200+
fields("target_lang", "de", "output_format", "docx"));
201+
client.translateDocumentUpload(input, null, "de", options);
202+
assertPartNames("/v2/document", "file", "target_lang", "output_format");
203+
}
204+
162205
@Test
163206
void sendsGlossaryIdsJoinedByCommaAndExtraBodyParametersLast() throws Exception {
164207
File input = writeInput("example.txt", "a");
@@ -350,6 +393,23 @@ void uploadsPollsAndDownloadsWhenTranslatingAFile() throws Exception {
350393
assertEquals("Protonenstrahl", Fixtures.readFile(output));
351394
}
352395

396+
@Test
397+
void sendsEnableWatermarkWhenTranslatingAFile() throws Exception {
398+
File input = writeInput("example.txt", "a");
399+
File output = tempDir.resolve("out.txt").toFile();
400+
expectUpload(
401+
"/v2/document/",
402+
"example.txt",
403+
"a".getBytes(StandardCharsets.UTF_8),
404+
fields("target_lang", "de", "enable_watermark", "true"));
405+
wm.stubFor(post("/v2/document/D1").willReturn(okJson(DONE)));
406+
wm.stubFor(
407+
post("/v2/document/D1/result").willReturn(aResponse().withStatus(200).withBody("b")));
408+
client.translateDocument(
409+
input, output, null, "de", new DocumentTranslationOptions().setEnableWatermark(true));
410+
assertPartNames("/v2/document/", "file", "target_lang", "enable_watermark");
411+
}
412+
353413
@Test
354414
void uploadsStreamsToThePathWithATrailingSlashWhenTranslatingStreams() throws Exception {
355415
expectUpload(

0 commit comments

Comments
 (0)