Skip to content

Commit 07c1d10

Browse files
feat: support glossaryIds and document style-rule/translation-memory options
1 parent 9c41d7e commit 07c1d10

10 files changed

Lines changed: 474 additions & 9 deletions

File tree

‎.gitlab-ci.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ include:
33
- project: '${CI_PROJECT_NAMESPACE}/ci-libs-for-client-libraries'
44
file:
55
- '/${CI_PROJECT_NAME}/.gitlab-ci.yml'
6-
- project: 'deepl/ops/ci-cd-infrastructure/gitlab-ci-lib'
6+
- project: 'deepl-org/deepl/devex/gitlab-ci-lib'
77
file:
88
- '/templates/.secret-detection.yml'
99
- '/templates/.gitlab-release.yml'

‎CHANGELOG.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ 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 support for using multiple glossaries in text and document translation
10+
via `setGlossaryIds()`/`setGlossaries()` (up to 5 glossaries) in
11+
`TextTranslationOptions` and `DocumentTranslationOptions`.
12+
- Added support for style rules in document translation via
13+
`setStyleRule()`/`setStyleId()` in `DocumentTranslationOptions`.
14+
- Added support for translation memories in document translation via
15+
`setTranslationMemory()`/`setTranslationMemoryId()`/`setTranslationMemoryThreshold()`
16+
in `DocumentTranslationOptions`.
17+
18+
### Fixed
19+
- Fixed incorrect example texts in the test suite for several languages (Danish,
20+
Indonesian, Japanese, Portuguese, and Russian) to match the mock server.
821

922
## [1.16.0] - 2026-04-09
1023
### Added

‎README.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ a `TextTranslationOptions`, with the following setters:
164164
`listGlossaries()` or `listMultilingualGlossaries()`).
165165
- `setGlossaryId()` is also available for backward-compatibility, accepting
166166
a string containing the glossary ID.
167+
- `setGlossaryIds()`: specifies multiple glossaries to use with translation
168+
(up to 5), as a list or varargs of glossary ID strings. Glossaries are applied
169+
in the order provided (first match wins). `setGlossaries()` is also available,
170+
accepting `IGlossary` objects. This option requires a source language and
171+
cannot be combined with `setGlossary()`/`setGlossaryId()`.
167172
- `setStyleRule()`: specifies a style rule to use with translation, as a string
168173
containing the ID of the style rule, or a `StyleRuleInfo` object.
169174
- `setStyleId()` is also available, accepting a string containing the style rule ID.
@@ -323,6 +328,15 @@ arguments, `translateDocument()` accepts an optional
323328
in [Text translation options](#text-translation-options).
324329
- `setGlossaryId()`: same as
325330
in [Text translation options](#text-translation-options).
331+
- `setGlossaryIds()`/`setGlossaries()`: same as
332+
in [Text translation options](#text-translation-options). Specifies multiple
333+
glossaries (up to 5) to use with document translation.
334+
- `setStyleRule()`/`setStyleId()`: same as
335+
in [Text translation options](#text-translation-options). Document translation
336+
now supports style rules.
337+
- `setTranslationMemory()`/`setTranslationMemoryId()`/`setTranslationMemoryThreshold()`:
338+
same as in [Text translation options](#text-translation-options). Document
339+
translation now supports translation memories.
326340

327341
### Glossaries
328342

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

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
// license that can be found in the LICENSE file.
44
package com.deepl.api;
55

6+
import java.util.ArrayList;
7+
import java.util.Arrays;
8+
import java.util.List;
9+
610
/**
711
* Options to control document translation behaviour. These options may be provided to {@link
812
* Translator#translateDocument} overloads.
@@ -16,6 +20,10 @@
1620
public class DocumentTranslationOptions extends BaseRequestOptions {
1721
private Formality formality;
1822
private String glossaryId;
23+
private List<String> glossaryIds;
24+
private String styleId;
25+
private String translationMemoryId;
26+
private Integer translationMemoryThreshold;
1927

2028
/**
2129
* Sets whether translations should lean toward formal or informal language. This option is only
@@ -56,6 +64,102 @@ public DocumentTranslationOptions setGlossary(String glossaryId) {
5664
return this;
5765
}
5866

67+
/**
68+
* Sets the list of glossary IDs to use with the translation, up to a maximum of 5. Glossaries are
69+
* applied in the order provided (first match wins). By default, this value is <code>null</code>
70+
* and no glossaries are used. This option requires a source language to be set and cannot be
71+
* combined with {@link #setGlossaryId} or {@link #setGlossary}.
72+
*/
73+
public DocumentTranslationOptions setGlossaryIds(List<String> glossaryIds) {
74+
this.glossaryIds = glossaryIds;
75+
return this;
76+
}
77+
78+
/**
79+
* Sets the list of glossary IDs to use with the translation, up to a maximum of 5. Glossaries are
80+
* applied in the order provided (first match wins). By default, this value is <code>null</code>
81+
* and no glossaries are used. This option requires a source language to be set and cannot be
82+
* combined with {@link #setGlossaryId} or {@link #setGlossary}.
83+
*/
84+
public DocumentTranslationOptions setGlossaryIds(String... glossaryIds) {
85+
this.glossaryIds = Arrays.asList(glossaryIds);
86+
return this;
87+
}
88+
89+
/**
90+
* Sets the list of glossaries to use with the translation, up to a maximum of 5. Glossaries are
91+
* applied in the order provided (first match wins). By default, this value is <code>null</code>
92+
* and no glossaries are used. This option requires a source language to be set and cannot be
93+
* combined with {@link #setGlossaryId} or {@link #setGlossary}.
94+
*/
95+
public DocumentTranslationOptions setGlossaries(IGlossary... glossaries) {
96+
List<String> ids = new ArrayList<>();
97+
for (IGlossary glossary : glossaries) {
98+
if (glossary == null) {
99+
throw new IllegalArgumentException("glossaries must not contain null");
100+
}
101+
ids.add(glossary.getGlossaryId());
102+
}
103+
this.glossaryIds = ids;
104+
return this;
105+
}
106+
107+
/**
108+
* Sets the ID of a style rule to use with the translation. By default, this value is <code>
109+
* null</code> and no style rule is used.
110+
*/
111+
public DocumentTranslationOptions setStyleId(String styleId) {
112+
this.styleId = styleId;
113+
return this;
114+
}
115+
116+
/**
117+
* Sets the style rule to use with the translation. By default, this value is <code>null</code>
118+
* and no style rule is used.
119+
*/
120+
public DocumentTranslationOptions setStyleRule(StyleRuleInfo styleRule) {
121+
if (styleRule == null) {
122+
throw new IllegalArgumentException("styleRule must not be null");
123+
}
124+
return setStyleId(styleRule.getStyleId());
125+
}
126+
127+
/**
128+
* Sets the ID of a translation memory to use with the translation. By default, this value is
129+
* <code>null</code> and no translation memory is used.
130+
*/
131+
public DocumentTranslationOptions setTranslationMemoryId(String translationMemoryId) {
132+
this.translationMemoryId = translationMemoryId;
133+
return this;
134+
}
135+
136+
/**
137+
* Sets the translation memory to use with the translation. By default, this value is <code>null
138+
* </code> and no translation memory is used.
139+
*/
140+
public DocumentTranslationOptions setTranslationMemory(TranslationMemoryInfo translationMemory) {
141+
if (translationMemory == null) {
142+
throw new IllegalArgumentException("translationMemory must not be null");
143+
}
144+
return setTranslationMemoryId(translationMemory.getTranslationMemoryId());
145+
}
146+
147+
/**
148+
* Sets the threshold for translation memory matches. By default, this value is <code>null</code>
149+
* and the API default threshold is used. Note: a translation memory ID must also be set via
150+
* {@link #setTranslationMemoryId} or {@link #setTranslationMemory}, otherwise an error will be
151+
* thrown at translation time.
152+
*/
153+
public DocumentTranslationOptions setTranslationMemoryThreshold(
154+
Integer translationMemoryThreshold) {
155+
if (translationMemoryThreshold != null
156+
&& (translationMemoryThreshold < 0 || translationMemoryThreshold > 100)) {
157+
throw new IllegalArgumentException("translationMemoryThreshold must be between 0 and 100");
158+
}
159+
this.translationMemoryThreshold = translationMemoryThreshold;
160+
return this;
161+
}
162+
59163
/** Gets the current formality setting. */
60164
public Formality getFormality() {
61165
return formality;
@@ -65,4 +169,24 @@ public Formality getFormality() {
65169
public String getGlossaryId() {
66170
return glossaryId;
67171
}
172+
173+
/** Gets the current list of glossary IDs. */
174+
public List<String> getGlossaryIds() {
175+
return glossaryIds;
176+
}
177+
178+
/** Gets the current style rule ID. */
179+
public String getStyleId() {
180+
return styleId;
181+
}
182+
183+
/** Gets the current translation memory ID. */
184+
public String getTranslationMemoryId() {
185+
return translationMemoryId;
186+
}
187+
188+
/** Gets the current translation memory threshold. */
189+
public Integer getTranslationMemoryThreshold() {
190+
return translationMemoryThreshold;
191+
}
68192
}

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
// license that can be found in the LICENSE file.
44
package com.deepl.api;
55

6+
import java.util.ArrayList;
7+
import java.util.Arrays;
8+
import java.util.List;
9+
610
/**
711
* Options to control text translation behaviour. These options may be provided to {@link
812
* Translator#translateText} overloads.
@@ -16,6 +20,7 @@
1620
public class TextTranslationOptions extends BaseRequestOptions {
1721
private Formality formality;
1822
private String glossaryId;
23+
private List<String> glossaryIds;
1924
private String styleId;
2025
private String translationMemoryId;
2126
private Integer translationMemoryThreshold;
@@ -70,6 +75,46 @@ public TextTranslationOptions setGlossary(String glossaryId) {
7075
return this;
7176
}
7277

78+
/**
79+
* Sets the list of glossary IDs to use with the translation, up to a maximum of 5. Glossaries are
80+
* applied in the order provided (first match wins). By default, this value is <code>null</code>
81+
* and no glossaries are used. This option requires a source language to be set and cannot be
82+
* combined with {@link #setGlossaryId} or {@link #setGlossary}.
83+
*/
84+
public TextTranslationOptions setGlossaryIds(List<String> glossaryIds) {
85+
this.glossaryIds = glossaryIds;
86+
return this;
87+
}
88+
89+
/**
90+
* Sets the list of glossary IDs to use with the translation, up to a maximum of 5. Glossaries are
91+
* applied in the order provided (first match wins). By default, this value is <code>null</code>
92+
* and no glossaries are used. This option requires a source language to be set and cannot be
93+
* combined with {@link #setGlossaryId} or {@link #setGlossary}.
94+
*/
95+
public TextTranslationOptions setGlossaryIds(String... glossaryIds) {
96+
this.glossaryIds = Arrays.asList(glossaryIds);
97+
return this;
98+
}
99+
100+
/**
101+
* Sets the list of glossaries to use with the translation, up to a maximum of 5. Glossaries are
102+
* applied in the order provided (first match wins). By default, this value is <code>null</code>
103+
* and no glossaries are used. This option requires a source language to be set and cannot be
104+
* combined with {@link #setGlossaryId} or {@link #setGlossary}.
105+
*/
106+
public TextTranslationOptions setGlossaries(IGlossary... glossaries) {
107+
List<String> ids = new ArrayList<>();
108+
for (IGlossary glossary : glossaries) {
109+
if (glossary == null) {
110+
throw new IllegalArgumentException("glossaries must not contain null");
111+
}
112+
ids.add(glossary.getGlossaryId());
113+
}
114+
this.glossaryIds = ids;
115+
return this;
116+
}
117+
73118
/**
74119
* Sets the ID of a style rule to use with the translation. By default, this value is <code>
75120
* null</code> and no style rule is used.
@@ -84,6 +129,9 @@ public TextTranslationOptions setStyleId(String styleId) {
84129
* and no style rule is used.
85130
*/
86131
public TextTranslationOptions setStyleRule(StyleRuleInfo styleRule) {
132+
if (styleRule == null) {
133+
throw new IllegalArgumentException("styleRule must not be null");
134+
}
87135
return setStyleId(styleRule.getStyleId());
88136
}
89137

@@ -242,6 +290,11 @@ public String getGlossaryId() {
242290
return glossaryId;
243291
}
244292

293+
/** Gets the current list of glossary IDs. */
294+
public List<String> getGlossaryIds() {
295+
return glossaryIds;
296+
}
297+
245298
/** Gets the current style rule ID. */
246299
public String getStyleId() {
247300
return styleId;

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

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,8 @@ private static ArrayList<KeyValuePair<String, String>> createHttpParams(
795795
sourceLang,
796796
targetLang,
797797
options != null ? options.getFormality() : null,
798-
options != null ? options.getGlossaryId() : null);
798+
options != null ? options.getGlossaryId() : null,
799+
options != null ? options.getGlossaryIds() : null);
799800
texts.forEach(
800801
(text) -> {
801802
if (text.isEmpty()) throw new IllegalArgumentException("text must not be empty");
@@ -892,7 +893,27 @@ protected static ArrayList<KeyValuePair<String, String>> createHttpParams(
892893
sourceLang,
893894
targetLang,
894895
options != null ? options.getFormality() : null,
895-
options != null ? options.getGlossaryId() : null);
896+
options != null ? options.getGlossaryId() : null,
897+
options != null ? options.getGlossaryIds() : null);
898+
899+
if (options != null) {
900+
if (options.getStyleId() != null) {
901+
params.add(new KeyValuePair<>("style_id", options.getStyleId()));
902+
}
903+
if (options.getTranslationMemoryId() != null) {
904+
params.add(new KeyValuePair<>("translation_memory_id", options.getTranslationMemoryId()));
905+
}
906+
if (options.getTranslationMemoryThreshold() != null) {
907+
if (options.getTranslationMemoryId() == null) {
908+
throw new IllegalArgumentException(
909+
"translationMemoryThreshold requires translationMemoryId");
910+
}
911+
params.add(
912+
new KeyValuePair<>(
913+
"translation_memory_threshold",
914+
options.getTranslationMemoryThreshold().toString()));
915+
}
916+
}
896917

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

@@ -908,13 +929,15 @@ protected static ArrayList<KeyValuePair<String, String>> createHttpParams(
908929
* @param targetLang Language code of the desired output language.
909930
* @param formality Formality option for translation.
910931
* @param glossaryId ID of glossary to use for translation.
932+
* @param glossaryIds List of glossary IDs to use for translation.
911933
* @return Iterable of parameters for HTTP request.
912934
*/
913935
protected static ArrayList<KeyValuePair<String, String>> createHttpParamsCommon(
914936
@Nullable String sourceLang,
915937
String targetLang,
916938
@Nullable Formality formality,
917-
@Nullable String glossaryId) {
939+
@Nullable String glossaryId,
940+
@Nullable List<String> glossaryIds) {
918941
targetLang = LanguageCode.standardize(targetLang);
919942
sourceLang = sourceLang == null ? null : LanguageCode.standardize(sourceLang);
920943
checkValidLanguages(sourceLang, targetLang);
@@ -953,6 +976,20 @@ protected static ArrayList<KeyValuePair<String, String>> createHttpParamsCommon(
953976
params.add(new KeyValuePair<>("glossary_id", glossaryId));
954977
}
955978

979+
if (glossaryIds != null && !glossaryIds.isEmpty()) {
980+
if (glossaryId != null) {
981+
throw new IllegalArgumentException(
982+
"glossaryIds cannot be used together with glossaryId; use one or the other");
983+
}
984+
if (sourceLang == null) {
985+
throw new IllegalArgumentException("sourceLang is required if using glossaries");
986+
}
987+
if (glossaryIds.size() > 5) {
988+
throw new IllegalArgumentException("glossaryIds cannot contain more than 5 glossary IDs");
989+
}
990+
params.add(new KeyValuePair<>("glossary_ids", String.join(",", glossaryIds)));
991+
}
992+
956993
return params;
957994
}
958995

0 commit comments

Comments
 (0)