33// license that can be found in the LICENSE file.
44package 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.
1620public 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}
0 commit comments