Skip to content

Commit 81cea4e

Browse files
hive-botclaude
andcommitted
feat: add style rule object, configured-rules map and options overloads
Add StyleRuleInfo overloads of the eight style rule methods that take a style rule ID, and CustomInstruction overloads of the get, update and delete custom instruction methods. Add createStyleRule() and updateStyleRuleConfiguredRules() overloads that take the configured rules as a Map<String, Map<String, String>> sent as given, and deprecate the overloads taking ConfiguredRules. Add CreateStyleRuleOptions, UpdateStyleRuleNameOptions, UpdateStyleRuleConfiguredRulesOptions, CreateStyleRuleCustomInstructionOptions and UpdateStyleRuleCustomInstructionOptions, whose extra body parameters are added to the request last. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 29aa380 commit 81cea4e

9 files changed

Lines changed: 920 additions & 63 deletions

‎CHANGELOG.md‎

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

77
## [Unreleased]
88
### Added
9+
- Added overloads of `getStyleRule()`, `updateStyleRuleName()`,
10+
`deleteStyleRule()`, `updateStyleRuleConfiguredRules()` and the four style
11+
rule custom instruction methods that take a `StyleRuleInfo` object, and
12+
overloads of `getStyleRuleCustomInstruction()`,
13+
`updateStyleRuleCustomInstruction()` and `deleteStyleRuleCustomInstruction()`
14+
that take a `CustomInstruction` object.
15+
- Added `createStyleRule()` and `updateStyleRuleConfiguredRules()` overloads
16+
that take the configured rules as a `Map<String, Map<String, String>>`, sent
17+
as given, so categories and rules beyond the fields of `ConfiguredRules` can
18+
be sent.
19+
- Added `CreateStyleRuleOptions`, `UpdateStyleRuleNameOptions`,
20+
`UpdateStyleRuleConfiguredRulesOptions`,
21+
`CreateStyleRuleCustomInstructionOptions` and
22+
`UpdateStyleRuleCustomInstructionOptions`, and overloads of the matching style
23+
rule methods that take them; their extra body parameters are added to the
24+
request last.
925
- Added `DeepLClient.updateMultilingualGlossary()` and
1026
`UpdateMultilingualGlossaryOptions`, which rename a glossary and merge
1127
dictionaries into it in one request, sending only the fields that are set.
@@ -156,6 +172,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
156172
languages, including the bare `en` and `pt` as target languages.
157173

158174
### Deprecated
175+
- `createStyleRule(String, String, ConfiguredRules, List)` and
176+
`updateStyleRuleConfiguredRules(String, ConfiguredRules)` are deprecated; use
177+
the overloads that take a `Map<String, Map<String, String>>` instead.
159178
- Deprecated `Translator.getLanguages(LanguageType)` and the `LanguageType`
160179
enum. Use `getSourceLanguages()` or `getTargetLanguages()` instead. They
161180
will be removed in the next major version.

‎README.md‎

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -910,27 +910,38 @@ your account, each with a user-specified name and a uniquely-assigned ID.
910910

911911
Use `createStyleRule()` to create a new style rule. You must specify a name and
912912
language code. You may optionally provide configured rules and custom
913-
instructions:
913+
instructions. Configured rules are a `Map<String, Map<String, String>>` from
914+
category to rule to value, in the API's snake_case form (for example
915+
`"dates_and_times"` → `"calendar_era"` → `"use_bc_and_ad"`), and are sent as
916+
given, so new categories and rules can be used as soon as the API supports
917+
them. The last argument is a `CreateStyleRuleOptions` object or `null`; its
918+
`setExtraBodyParameters()` adds further body parameters, sent last. The
919+
overload taking a `ConfiguredRules` object is deprecated; use the `Map`
920+
overload instead.
914921

915922
```java
916923
class Example { // Continuing class Example from above
917924
public void createStyleRuleExample() throws Exception {
918925
// Create a simple style rule
919-
StyleRuleInfo rule = client.createStyleRule("My Style", "en", null, null);
926+
StyleRuleInfo rule = client.createStyleRule("My Style", "en", null, null, null);
920927
System.out.println("Created: " + rule.getStyleId());
921928

922-
// Create with custom instructions
929+
// Create with configured rules and custom instructions
930+
Map<String, Map<String, String>> configuredRules = new HashMap<>();
931+
configuredRules.put("dates_and_times",
932+
Collections.singletonMap("calendar_era", "use_bc_and_ad"));
923933
List<CustomInstruction> instructions = new ArrayList<>();
924934
instructions.add(new CustomInstruction("Formal tone", "Use formal language", null));
925935
StyleRuleInfo ruleWithInstructions = client.createStyleRule(
926-
"Formal Style", "en", null, instructions);
936+
"Formal Style", "en", configuredRules, instructions, null);
927937
}
928938
}
929939
```
930940

931941
#### Retrieving and listing style rules
932942

933-
`getStyleRule()` retrieves a single style rule by its ID. `getAllStyleRules()`
943+
`getStyleRule()` retrieves a single style rule by its ID or `StyleRuleInfo`
944+
object. `getAllStyleRules()`
934945
returns a list of `StyleRuleInfo` objects corresponding to all of your stored
935946
style rules. The method accepts optional parameters: `page` (page number for
936947
pagination, 0-indexed), `pageSize` (number of items per page), and `detailed`.
@@ -966,7 +977,18 @@ class Example { // Continuing class Example from above
966977
#### Updating a style rule
967978

968979
Use `updateStyleRuleName()` to rename a style rule, and
969-
`updateStyleRuleConfiguredRules()` to replace its configured rules:
980+
`updateStyleRuleConfiguredRules()` to replace its configured rules. The
981+
configured rules are a `Map<String, Map<String, String>>` sent as given as the
982+
request body; the overload taking a `ConfiguredRules` object is deprecated.
983+
Both methods have overloads that take an options object
984+
(`UpdateStyleRuleNameOptions`, `UpdateStyleRuleConfiguredRulesOptions`) whose
985+
extra body parameters are sent last; for configured rules they are added to the
986+
body as further top-level keys.
987+
988+
Every method that takes a style rule ID (`getStyleRule()`,
989+
`updateStyleRuleName()`, `updateStyleRuleConfiguredRules()`, `deleteStyleRule()`
990+
and the custom instruction methods) also accepts a `StyleRuleInfo` object. IDs
991+
are URL-encoded in the request path.
970992

971993
```java
972994
class Example { // Continuing class Example from above
@@ -977,18 +999,31 @@ class Example { // Continuing class Example from above
977999
StyleRuleInfo updated = client.updateStyleRuleName(styleId, "New Name");
9781000
System.out.println("Updated name: " + updated.getName());
9791001

980-
// Update configured rules
981-
ConfiguredRules configuredRules = new ConfiguredRules();
1002+
// Rename, passing the StyleRuleInfo object and extra body parameters
1003+
client.updateStyleRuleName(updated, "Newer Name",
1004+
new UpdateStyleRuleNameOptions().setExtraBodyParameters(
1005+
Collections.singletonMap("param", "value")));
1006+
1007+
// Replace the configured rules
1008+
Map<String, Map<String, String>> configuredRules = new HashMap<>();
1009+
configuredRules.put("punctuation",
1010+
Collections.singletonMap("periods_in_academic_degrees", "do_not_use"));
9821011
StyleRuleInfo updatedRules = client.updateStyleRuleConfiguredRules(
983-
styleId, configuredRules);
1012+
styleId, configuredRules, null);
9841013
}
9851014
}
9861015
```
9871016

9881017
#### Managing custom instructions
9891018

9901019
Custom instructions can be created, retrieved, updated, and deleted individually
991-
within a style rule:
1020+
within a style rule. The style rule can be given as an ID or a `StyleRuleInfo`
1021+
object, and the custom instruction as an ID or a `CustomInstruction` object.
1022+
`createStyleRuleCustomInstruction()` and `updateStyleRuleCustomInstruction()`
1023+
have overloads that take an options object
1024+
(`CreateStyleRuleCustomInstructionOptions`,
1025+
`UpdateStyleRuleCustomInstructionOptions`) whose extra body parameters are sent
1026+
last:
9921027

9931028
```java
9941029
class Example { // Continuing class Example from above
@@ -1009,8 +1044,8 @@ class Example { // Continuing class Example from above
10091044
CustomInstruction updated = client.updateStyleRuleCustomInstruction(
10101045
styleId, instructionId, "Updated label", "Updated prompt", null);
10111046

1012-
// Delete the custom instruction
1013-
client.deleteStyleRuleCustomInstruction(styleId, instructionId);
1047+
// Delete the custom instruction, passing the object instead of its ID
1048+
client.deleteStyleRuleCustomInstruction(styleId, updated);
10141049
}
10151050
}
10161051
```
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
8+
/**
9+
* Options for {@link DeepLClient#createStyleRuleCustomInstruction(String, String, String, String,
10+
* CreateStyleRuleCustomInstructionOptions)}.
11+
*/
12+
public class CreateStyleRuleCustomInstructionOptions extends BaseRequestOptions {
13+
/** {@inheritDoc} */
14+
@Override
15+
public CreateStyleRuleCustomInstructionOptions setExtraBodyParameters(
16+
Map<String, String> extraBodyParameters) {
17+
super.setExtraBodyParameters(extraBodyParameters);
18+
return this;
19+
}
20+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
8+
/**
9+
* Options for {@link DeepLClient#createStyleRule(String, String, java.util.Map, java.util.List,
10+
* CreateStyleRuleOptions)}.
11+
*/
12+
public class CreateStyleRuleOptions extends BaseRequestOptions {
13+
/** {@inheritDoc} */
14+
@Override
15+
public CreateStyleRuleOptions setExtraBodyParameters(Map<String, String> extraBodyParameters) {
16+
super.setExtraBodyParameters(extraBodyParameters);
17+
return this;
18+
}
19+
}

0 commit comments

Comments
 (0)