@@ -657,42 +657,128 @@ Style rules allow you to customize your translations using a managed, shared lis
657657of rules for style, formatting, and more. Multiple style rules can be stored with
658658your account, each with a user-specified name and a uniquely-assigned ID.
659659
660- #### Creating and managing style rules
660+ #### Creating a style rule
661661
662- Currently style rules must be created and managed in the DeepL UI via
663- https://www.deepl.com/en/custom-rules . Full CRUD functionality via the APIs will
664- come shortly.
662+ Use ` createStyleRule() ` to create a new style rule. You must specify a name and
663+ language code. You may optionally provide configured rules and custom
664+ instructions:
665665
666- #### Listing all style rules
666+ ``` java
667+ class Example { // Continuing class Example from above
668+ public void createStyleRuleExample () throws Exception {
669+ // Create a simple style rule
670+ StyleRuleInfo rule = client. createStyleRule(" My Style" , " en" , null , null );
671+ System . out. println(" Created: " + rule. getStyleId());
672+
673+ // Create with custom instructions
674+ List<CustomInstruction > instructions = new ArrayList<> ();
675+ instructions. add(new CustomInstruction (" Formal tone" , " Use formal language" , null ));
676+ StyleRuleInfo ruleWithInstructions = client. createStyleRule(
677+ " Formal Style" , " en" , null , instructions);
678+ }
679+ }
680+ ```
667681
668- ` getAllStyleRules() ` returns a list of ` StyleRuleInfo ` objects
669- corresponding to all of your stored style rules. The method accepts optional
670- parameters: ` page ` (page number for pagination, 0-indexed), ` pageSize ` (number
671- of items per page), and ` detailed ` (whether to include detailed configuration
672- rules in the ` configuredRules ` property).
682+ #### Retrieving and listing style rules
683+
684+ ` getStyleRule() ` retrieves a single style rule by its ID. ` getAllStyleRules() `
685+ returns a list of ` StyleRuleInfo ` objects corresponding to all of your stored
686+ style rules. The method accepts optional parameters: ` page ` (page number for
687+ pagination, 0-indexed), ` pageSize ` (number of items per page), and ` detailed ` .
688+ When ` true ` , the response includes ` configuredRules ` and ` customInstructions `
689+ for each style rule. When ` false ` (default), these fields are omitted for faster
690+ responses.
673691
674692``` java
675693class Example { // Continuing class Example from above
676- public void styleRulesExample () throws Exception {
694+ public void listStyleRulesExample () throws Exception {
695+ // Get a single style rule by ID
696+ StyleRuleInfo rule = client. getStyleRule(" dca2e053-8ae5-45e6-a0d2-881156e7f4e4" );
697+ System . out. println(rule. getName());
698+
677699 // Get all style rules
678700 List<StyleRuleInfo > styleRules = client. getAllStyleRules();
679- for (StyleRuleInfo rule : styleRules) {
680- System . out. println(String . format(" %s (%s)" , rule . getName(), rule . getStyleId()));
701+ for (StyleRuleInfo r : styleRules) {
702+ System . out. println(String . format(" %s (%s)" , r . getName(), r . getStyleId()));
681703 }
682704
683705 // Get style rules with detailed configuration
684706 List<StyleRuleInfo > styleRulesDetailed = client. getAllStyleRules(null , null , true );
685- for (StyleRuleInfo rule : styleRulesDetailed) {
686- if (rule . getConfiguredRules() != null && rule . getConfiguredRules(). getNumbers() != null ) {
707+ for (StyleRuleInfo r : styleRulesDetailed) {
708+ if (r . getConfiguredRules() != null && r . getConfiguredRules(). getNumbers() != null ) {
687709 System . out. println(String . format(" Number formatting rules: %s" ,
688- String . join(" , " , rule . getConfiguredRules(). getNumbers(). keySet())));
710+ String . join(" , " , r . getConfiguredRules(). getNumbers(). keySet())));
689711 }
690712 }
691713 }
692714}
693715```
694716
695- #### Using a stored style rule
717+ #### Updating a style rule
718+
719+ Use ` updateStyleRuleName() ` to rename a style rule, and
720+ ` updateStyleRuleConfiguredRules() ` to replace its configured rules:
721+
722+ ``` java
723+ class Example { // Continuing class Example from above
724+ public void updateStyleRuleExample () throws Exception {
725+ String styleId = " dca2e053-8ae5-45e6-a0d2-881156e7f4e4" ;
726+
727+ // Update the name
728+ StyleRuleInfo updated = client. updateStyleRuleName(styleId, " New Name" );
729+ System . out. println(" Updated name: " + updated. getName());
730+
731+ // Update configured rules
732+ ConfiguredRules configuredRules = new ConfiguredRules ();
733+ StyleRuleInfo updatedRules = client. updateStyleRuleConfiguredRules(
734+ styleId, configuredRules);
735+ }
736+ }
737+ ```
738+
739+ #### Managing custom instructions
740+
741+ Custom instructions can be created, retrieved, updated, and deleted individually
742+ within a style rule:
743+
744+ ``` java
745+ class Example { // Continuing class Example from above
746+ public void customInstructionsExample () throws Exception {
747+ String styleId = " dca2e053-8ae5-45e6-a0d2-881156e7f4e4" ;
748+
749+ // Create a custom instruction
750+ CustomInstruction instruction = client. createStyleRuleCustomInstruction(
751+ styleId, " Formal tone" , " Always use formal language" , null );
752+ String instructionId = instruction. getId();
753+
754+ // Retrieve the custom instruction
755+ CustomInstruction retrieved = client. getStyleRuleCustomInstruction(
756+ styleId, instructionId);
757+ System . out. println(retrieved. getLabel());
758+
759+ // Update the custom instruction
760+ CustomInstruction updated = client. updateStyleRuleCustomInstruction(
761+ styleId, instructionId, " Updated label" , " Updated prompt" , null );
762+
763+ // Delete the custom instruction
764+ client. deleteStyleRuleCustomInstruction(styleId, instructionId);
765+ }
766+ }
767+ ```
768+
769+ #### Deleting a style rule
770+
771+ Use ` deleteStyleRule() ` to permanently remove a style rule from your account:
772+
773+ ``` java
774+ class Example { // Continuing class Example from above
775+ public void deleteStyleRuleExample () throws Exception {
776+ client. deleteStyleRule(" dca2e053-8ae5-45e6-a0d2-881156e7f4e4" );
777+ }
778+ }
779+ ```
780+
781+ #### Using a stored style rule in translations
696782
697783You can use a stored style rule for text translation by setting the ` styleRule `
698784argument to either the style rule ID or ` StyleRuleInfo ` object:
0 commit comments