Skip to content

Commit ad9356e

Browse files
hive-botclaude
andcommitted
feat: align the style profile options with the other SDKs
StyleProfileOptions becomes CreateStyleProfileOptions, and the new UpdateStyleProfileOptions extends it with setName(). updateStyleProfile() now takes (styleProfile, options), with an overload without options. Both options classes extend BaseRequestOptions; extra body parameters are added to the JSON body last and replace a field with the same key. The glossary, style rule and translation memory setters also accept the resource objects and send their IDs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 193542c commit ad9356e

8 files changed

Lines changed: 442 additions & 162 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5555
- Added style profile support to `DeepLClient` (`/v3/style_profiles`):
5656
`createStyleProfile()`, `listStyleProfiles()`, `getStyleProfile()`,
5757
`updateStyleProfile()` and `deleteStyleProfile()`, with the new classes
58-
`StyleProfile` and `StyleProfileOptions`. Options left `null` are not sent;
59-
an empty string clears the description or industry and an empty list
60-
unlinks all components of that kind.
58+
`StyleProfile`, `CreateStyleProfileOptions` and `UpdateStyleProfileOptions`
59+
(which adds `setName()`). Both options classes support
60+
`setExtraBodyParameters()`. `setGlossaryIds()`, `setStyleRuleIds()` and
61+
`setTranslationMemoryIds()` take a list of IDs or the `IGlossary`,
62+
`StyleRuleInfo` or `TranslationMemoryInfo` objects. Options left `null` are
63+
not sent; an empty string clears the description or industry and an empty
64+
list unlinks all components of that kind.
6165
- Added Spoken Terms support to `DeepLClient` (`/v3/spoken-terms`):
6266
`createSpokenTerms()`, `listSpokenTerms()`, `getSpokenTerms()`,
6367
`updateSpokenTerms()`, `getSpokenTermsEntries()`, `replaceSpokenTermsList()`,

‎README.md‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,9 +1005,14 @@ with `DeepLClient`; each has a user-specified name and a uniquely-assigned ID.
10051005
#### Creating a style profile
10061006

10071007
Use `createStyleProfile()` to create a style profile. Only the name is required.
1008-
Pass a `StyleProfileOptions` to set a description, an industry, the IDs of the
1009-
components to link, and whether the glossary order sets priority. If any of the
1010-
component IDs cannot be used, the request fails and no style profile is created.
1008+
Pass a `CreateStyleProfileOptions` to set a description, an industry, the
1009+
components to link, and whether the glossary order sets priority.
1010+
`setGlossaryIds()`, `setStyleRuleIds()` and `setTranslationMemoryIds()` take a
1011+
list of IDs or the objects themselves (`GlossaryInfo` or
1012+
`MultilingualGlossaryInfo`, `StyleRuleInfo`, `TranslationMemoryInfo`).
1013+
`setExtraBodyParameters()` adds fields to the JSON request body, replacing a
1014+
field with the same key. If any of the component IDs cannot be used, the
1015+
request fails and no style profile is created.
10111016

10121017
```java
10131018
class Example { // Continuing class Example from above
@@ -1019,7 +1024,7 @@ class Example { // Continuing class Example from above
10191024
// Create a style profile with a description and linked components
10201025
StyleProfile linked = client.createStyleProfile(
10211026
"Legal, German",
1022-
new StyleProfileOptions()
1027+
new CreateStyleProfileOptions()
10231028
.setDescription("Contract wording for the German market.")
10241029
.setIndustry("Legal")
10251030
.setGlossaryIds(Arrays.asList(
@@ -1028,6 +1033,11 @@ class Example { // Continuing class Example from above
10281033
.setGlossaryPriorityOrderEnabled(true)
10291034
.setStyleRuleIds(Arrays.asList("dca2e053-8ae5-45e6-a0d2-881156e7f4e4")));
10301035
System.out.println(linked.getStyleRuleIds());
1036+
1037+
// Link components by passing the objects instead of their IDs
1038+
StyleRuleInfo rule = client.getStyleRule("dca2e053-8ae5-45e6-a0d2-881156e7f4e4");
1039+
client.createStyleProfile(
1040+
"Legal, German (rules)", new CreateStyleProfileOptions().setStyleRuleIds(rule));
10311041
}
10321042
}
10331043
```
@@ -1062,9 +1072,9 @@ class Example { // Continuing class Example from above
10621072

10631073
#### Updating a style profile
10641074

1065-
`updateStyleProfile()` takes the ID or `StyleProfile` object, an optional new
1066-
name and an optional `StyleProfileOptions`. Fields left `null` are not sent and
1067-
stay unchanged. An empty string clears the description or industry. A component
1075+
`updateStyleProfile()` takes the ID or `StyleProfile` object and an optional
1076+
`UpdateStyleProfileOptions`, which has the setters of `CreateStyleProfileOptions`
1077+
plus `setName()`. Fields left `null` are not sent and stay unchanged. An empty string clears the description or industry. A component
10681078
list you send replaces the linked list in full; an empty list unlinks all
10691079
components of that kind.
10701080

@@ -1075,13 +1085,13 @@ class Example { // Continuing class Example from above
10751085

10761086
// Rename and set the industry; other fields are unchanged
10771087
client.updateStyleProfile(
1078-
profileId, "Legal, German (2026)", new StyleProfileOptions().setIndustry("Legal"));
1088+
profileId,
1089+
new UpdateStyleProfileOptions().setName("Legal, German (2026)").setIndustry("Legal"));
10791090

10801091
// Clear the description and unlink all style rules
10811092
StyleProfile updated = client.updateStyleProfile(
10821093
profileId,
1083-
null,
1084-
new StyleProfileOptions()
1094+
new UpdateStyleProfileOptions()
10851095
.setDescription("")
10861096
.setStyleRuleIds(Collections.emptyList()));
10871097
System.out.println(updated.getDescription()); // null
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
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.ArrayList;
7+
import java.util.List;
8+
import java.util.Map;
9+
import java.util.function.Function;
10+
import org.jetbrains.annotations.Nullable;
11+
12+
/**
13+
* Options for {@link DeepLClient#createStyleProfile(String, CreateStyleProfileOptions)}, also the
14+
* base of {@link UpdateStyleProfileOptions}.
15+
*
16+
* <p>A field left <code>null</code> is not sent, so an update keeps its current value. An empty
17+
* string clears the description or industry; an empty list unlinks all components of that kind. A
18+
* list that is sent replaces the linked list in full.
19+
*/
20+
public class CreateStyleProfileOptions extends BaseRequestOptions {
21+
private @Nullable String description;
22+
private @Nullable String industry;
23+
private @Nullable List<String> glossaryIds;
24+
private @Nullable List<String> styleRuleIds;
25+
private @Nullable List<String> translationMemoryIds;
26+
private @Nullable Boolean glossaryPriorityOrderEnabled;
27+
28+
/** Sets the description of the style profile; an empty string clears it. */
29+
public CreateStyleProfileOptions setDescription(@Nullable String description) {
30+
this.description = description;
31+
return this;
32+
}
33+
34+
/** Sets the industry of the style profile, for example "Legal"; an empty string clears it. */
35+
public CreateStyleProfileOptions setIndustry(@Nullable String industry) {
36+
this.industry = industry;
37+
return this;
38+
}
39+
40+
/**
41+
* Sets the IDs of the glossaries to link, in priority order; an empty list unlinks all
42+
* glossaries.
43+
*/
44+
public CreateStyleProfileOptions setGlossaryIds(@Nullable List<String> glossaryIds) {
45+
this.glossaryIds = glossaryIds;
46+
return this;
47+
}
48+
49+
/**
50+
* Sets the glossaries to link, in priority order, as {@link GlossaryInfo} or {@link
51+
* MultilingualGlossaryInfo} objects; their IDs are sent.
52+
*/
53+
public CreateStyleProfileOptions setGlossaryIds(IGlossary first, IGlossary... more) {
54+
this.glossaryIds = idsOf(first, more, IGlossary::getGlossaryId, "glossaries");
55+
return this;
56+
}
57+
58+
/** Sets the IDs of the style rules to link; an empty list unlinks all style rules. */
59+
public CreateStyleProfileOptions setStyleRuleIds(@Nullable List<String> styleRuleIds) {
60+
this.styleRuleIds = styleRuleIds;
61+
return this;
62+
}
63+
64+
/** Sets the style rules to link as {@link StyleRuleInfo} objects; their IDs are sent. */
65+
public CreateStyleProfileOptions setStyleRuleIds(StyleRuleInfo first, StyleRuleInfo... more) {
66+
this.styleRuleIds = idsOf(first, more, StyleRuleInfo::getStyleId, "style rules");
67+
return this;
68+
}
69+
70+
/**
71+
* Sets the IDs of the translation memories to link; an empty list unlinks all translation
72+
* memories.
73+
*/
74+
public CreateStyleProfileOptions setTranslationMemoryIds(
75+
@Nullable List<String> translationMemoryIds) {
76+
this.translationMemoryIds = translationMemoryIds;
77+
return this;
78+
}
79+
80+
/**
81+
* Sets the translation memories to link as {@link TranslationMemoryInfo} objects; their IDs are
82+
* sent.
83+
*/
84+
public CreateStyleProfileOptions setTranslationMemoryIds(
85+
TranslationMemoryInfo first, TranslationMemoryInfo... more) {
86+
this.translationMemoryIds =
87+
idsOf(first, more, TranslationMemoryInfo::getTranslationMemoryId, "translation memories");
88+
return this;
89+
}
90+
91+
/** Sets whether the linked glossaries are applied in the order of the glossary IDs. */
92+
public CreateStyleProfileOptions setGlossaryPriorityOrderEnabled(
93+
@Nullable Boolean glossaryPriorityOrderEnabled) {
94+
this.glossaryPriorityOrderEnabled = glossaryPriorityOrderEnabled;
95+
return this;
96+
}
97+
98+
/** {@inheritDoc} */
99+
@Override
100+
public CreateStyleProfileOptions setExtraBodyParameters(Map<String, String> extraBodyParameters) {
101+
super.setExtraBodyParameters(extraBodyParameters);
102+
return this;
103+
}
104+
105+
/** Gets the current description. */
106+
public @Nullable String getDescription() {
107+
return description;
108+
}
109+
110+
/** Gets the current industry. */
111+
public @Nullable String getIndustry() {
112+
return industry;
113+
}
114+
115+
/** Gets the current glossary IDs. */
116+
public @Nullable List<String> getGlossaryIds() {
117+
return glossaryIds;
118+
}
119+
120+
/** Gets the current style rule IDs. */
121+
public @Nullable List<String> getStyleRuleIds() {
122+
return styleRuleIds;
123+
}
124+
125+
/** Gets the current translation memory IDs. */
126+
public @Nullable List<String> getTranslationMemoryIds() {
127+
return translationMemoryIds;
128+
}
129+
130+
/** Gets the current glossary priority order setting. */
131+
public @Nullable Boolean getGlossaryPriorityOrderEnabled() {
132+
return glossaryPriorityOrderEnabled;
133+
}
134+
135+
// The separate first parameter keeps a zero-argument call off the object overloads.
136+
private static <T> List<String> idsOf(
137+
T first, T[] more, Function<T, String> getId, String description) {
138+
List<String> ids = new ArrayList<>();
139+
ids.add(idOf(first, getId, description));
140+
for (T item : more) {
141+
ids.add(idOf(item, getId, description));
142+
}
143+
return ids;
144+
}
145+
146+
private static <T> String idOf(@Nullable T item, Function<T, String> getId, String description) {
147+
if (item == null) {
148+
throw new IllegalArgumentException(description + " must not contain null");
149+
}
150+
return getId.apply(item);
151+
}
152+
}

0 commit comments

Comments
 (0)