Skip to content

Commit 073fdf1

Browse files
hive-botclaude
andcommitted
feat: add translation memory import options and overloads
Add CreateTranslationMemoryImportOptions and ImportTranslationMemoryOptions (both with extra body parameters), a content type for the import helper, byte[] import and OutputStream export overloads, job-object overloads of getTranslationMemoryJob() and waitUntilTranslationMemoryJobDone(), an exportTranslationMemoryToFilepath(TranslationMemoryInfo, File, Duration) overload and uploadTranslationMemoryFile(String, byte[]). Fields of TranslationMemoryJob that the API always returns are no longer @nullable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ab3b02d commit 073fdf1

7 files changed

Lines changed: 652 additions & 44 deletions

File tree

‎CHANGELOG.md‎

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

77
## [Unreleased]
88
### Added
9+
- Added `CreateTranslationMemoryImportOptions` (content type, display name,
10+
extra body parameters) and `createTranslationMemoryImport()` overloads taking
11+
only the file name and size, or an options object; extra body parameters are
12+
added to the request last.
13+
- Added `ImportTranslationMemoryOptions` (display name, content type, timeout,
14+
extra body parameters) and `importTranslationMemoryFromFilepath()` overloads
15+
taking it, with a `File` or with the file content as `byte[]` plus a file
16+
name. The content type is declared on the import job and sent with the upload.
17+
- Added `exportTranslationMemoryToFilepath()` overloads that write to an
18+
`OutputStream`, and one taking a `TranslationMemoryInfo`, a `File` and a
19+
timeout.
20+
- Added `getTranslationMemoryJob()` and `waitUntilTranslationMemoryJobDone()`
21+
overloads that take a `TranslationMemoryJob` object.
22+
- Added `uploadTranslationMemoryFile(String uploadUrl, byte[] fileContent)`,
23+
which uploads with the content type `application/xml`.
924
- Added overloads of `getStyleRule()`, `updateStyleRuleName()`,
1025
`deleteStyleRule()`, `updateStyleRuleConfiguredRules()` and the four style
1126
rule custom instruction methods that take a `StyleRuleInfo` object, and
@@ -163,6 +178,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
163178
`setExtraBodyParameters()`, added last to the `rephraseText()` request body.
164179

165180
### Changed
181+
- `TranslationMemoryJob.getProduct()`, `getOperation()`, `getCreationTime()`
182+
and `getUpdatedTime()` are no longer annotated `@Nullable`, as the API always
183+
returns these fields.
166184
- The bare target languages `en` and `pt` are no longer rejected
167185
client-side in text translation, document translation and rephrasing. The
168186
API translates them to `en-US` and `pt-PT` respectively.

‎README.md‎

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,29 @@ The optional timeout is the maximum time to wait for the import to finish; omit
13151315
it to wait indefinitely. The job status is polled every 5 seconds, so the
13161316
timeout is not accurate to the millisecond.
13171317

1318+
`ImportTranslationMemoryOptions` groups the import options: `setDisplayName()`,
1319+
`setContentType()` (declared when the job is created and sent with the upload;
1320+
the file is uploaded as `application/xml` if unset), `setTimeout()` and
1321+
`setExtraBodyParameters()`, whose parameters are added to the import request
1322+
body last. Instead of a `File`, you can pass the file content as a `byte[]`
1323+
together with a file name:
1324+
1325+
```java
1326+
class Example { // Continuing class Example from above
1327+
public void importTranslationMemoryOptionsExample() throws Exception {
1328+
ImportTranslationMemoryOptions options = new ImportTranslationMemoryOptions()
1329+
.setDisplayName("Legal TM")
1330+
.setContentType("application/xml")
1331+
.setTimeout(Duration.ofSeconds(300));
1332+
TranslationMemoryJob job = client.importTranslationMemoryFromFilepath(
1333+
new File("/path/to/legal.tmx"), options);
1334+
byte[] fileContent = Files.readAllBytes(Paths.get("/path/to/other.tmx"));
1335+
TranslationMemoryJob other = client.importTranslationMemoryFromFilepath(
1336+
fileContent, "other.tmx", options);
1337+
}
1338+
}
1339+
```
1340+
13181341
The three steps are also available separately, for example to upload the file
13191342
yourself or to poll for progress. `createTranslationMemoryImport()` returns an
13201343
upload URL that the file must be uploaded to before processing starts, then
@@ -1327,7 +1350,8 @@ class Example { // Continuing class Example from above
13271350
byte[] fileContent = Files.readAllBytes(inputFile.toPath());
13281351

13291352
TranslationMemoryImport created = client.createTranslationMemoryImport(
1330-
inputFile.getName(), fileContent.length, null, "Legal TM");
1353+
inputFile.getName(), fileContent.length,
1354+
new CreateTranslationMemoryImportOptions().setDisplayName("Legal TM"));
13311355
// Until the file is uploaded, the job status is AwaitingInput
13321356
client.uploadTranslationMemoryFile(created, fileContent);
13331357

@@ -1337,6 +1361,14 @@ class Example { // Continuing class Example from above
13371361
}
13381362
```
13391363

1364+
`CreateTranslationMemoryImportOptions` takes the optional `setContentType()`,
1365+
`setDisplayName()` and `setExtraBodyParameters()`; the overload taking only the
1366+
file name and size uses none of them. `uploadTranslationMemoryFile()` accepts the
1367+
`TranslationMemoryImport` or its upload URL, and an optional content type that
1368+
defaults to `application/xml`. `getTranslationMemoryJob()` and
1369+
`waitUntilTranslationMemoryJobDone()` accept a job ID or a `TranslationMemoryJob`
1370+
object.
1371+
13401372
Note that an import job keeps reporting `AwaitingInput` for a while after its
13411373
file has been uploaded, because the API detects the upload asynchronously.
13421374
`waitUntilTranslationMemoryJobDone()` polls through that status like any other
@@ -1358,7 +1390,18 @@ class Example { // Continuing class Example from above
13581390
}
13591391
```
13601392

1361-
As with import, the timeout is optional; omit it to wait indefinitely.
1393+
As with import, the timeout is optional; omit it to wait indefinitely. Instead of
1394+
a `File`, you can pass an `OutputStream`, which is not closed:
1395+
1396+
```java
1397+
class Example { // Continuing class Example from above
1398+
public void exportTranslationMemoryToStreamExample() throws Exception {
1399+
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
1400+
TranslationMemoryJob job = client.exportTranslationMemoryToFilepath(
1401+
"YOUR_TM_ID", outputStream, Duration.ofSeconds(300));
1402+
}
1403+
}
1404+
```
13621405

13631406
As with import, the individual steps are available separately. Note that the API
13641407
may reuse a previously completed export of an unchanged translation memory,
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2026 DeepL SE (https://www.deepl.com)
2+
// Use of this source code is governed by an MIT
3+
// license that can be found in the LICENSE file.
4+
package com.deepl.api;
5+
6+
import java.util.Map;
7+
import org.jetbrains.annotations.Nullable;
8+
9+
/**
10+
* Options for {@link DeepLClient#createTranslationMemoryImport(String, long,
11+
* CreateTranslationMemoryImportOptions)}.
12+
*/
13+
public class CreateTranslationMemoryImportOptions extends BaseRequestOptions {
14+
private @Nullable String contentType;
15+
private @Nullable String displayName;
16+
17+
/**
18+
* Sets the MIME type of the file to import. By default, this value is <code>null</code> and the
19+
* API default "application/xml" is used.
20+
*/
21+
public CreateTranslationMemoryImportOptions setContentType(@Nullable String contentType) {
22+
this.contentType = contentType;
23+
return this;
24+
}
25+
26+
/** Gets the current content type. */
27+
public @Nullable String getContentType() {
28+
return contentType;
29+
}
30+
31+
/**
32+
* Sets the name of the resulting translation memory. By default, this value is <code>null</code>
33+
* and the API names the translation memory after the file.
34+
*/
35+
public CreateTranslationMemoryImportOptions setDisplayName(@Nullable String displayName) {
36+
this.displayName = displayName;
37+
return this;
38+
}
39+
40+
/** Gets the current display name. */
41+
public @Nullable String getDisplayName() {
42+
return displayName;
43+
}
44+
45+
/** {@inheritDoc} */
46+
@Override
47+
public CreateTranslationMemoryImportOptions setExtraBodyParameters(
48+
Map<String, String> extraBodyParameters) {
49+
super.setExtraBodyParameters(extraBodyParameters);
50+
return this;
51+
}
52+
}

0 commit comments

Comments
 (0)