Skip to main content

Building a completion action

The TranslationCompletionAction abstract class provides a flexible solution for executing custom logic when translations complete. Brightspot includes built-in actions (Draft, Publish, Workflow), and you can create custom actions for specific requirements.

Step 1: Extend TranslationCompletionAction

Create a class that extends TranslationCompletionAction:

1
@Recordable.DisplayName("Publish with Translation Author")
2
public abstract class TranslationAuthorCompletionAction extends TranslationCompletionAction {
3
// Implementation
4
}

Since TranslationCompletionAction extends Record, you can use standard Brightspot data modeling annotations.

Step 2: Add configuration fields (optional)

Add fields to your class for admin-configurable options. These appear when administrators configure completion actions in site settings.

1
@Recordable.DisplayName("Publish with Translation Author")
2
public abstract class TranslationAuthorCompletionActionWithFields extends TranslationCompletionAction {
3
4
@Note("Author selected here will be set as the content author for all translations")
5
private Author author;
6
}

For example, the built-in WorkflowCompletionAction allows admins to configure which workflow state translated content enters.

Step 3: Implement completeTranslation

Implement the completeTranslation method to define what happens when a translation completes:

1
@Override
2
protected void completeTranslation(Recordable newContent, TranslationLog log) {
3
// Apply custom logic to the translated content
4
newContent.as(HasAuthorData.class).setAuthor(author);
5
6
// Save the content (required)
7
Content.Static.publish(
8
newContent,
9
log.getSite(),
10
newContent.as(Content.ObjectModification.class).getPublishUser());
11
}

Method parameters

ParameterDescription
newContentThe translated content object
logInformation about the translation (user, service, metadata)

Responsibilities

Your implementation must:

  • Save the content to the database
  • Perform any custom logic needed

Your implementation does not need to:

  • Save the TranslationLog (handled by the system)

Helper methods

The createDraft helper method creates a Draft (revision) object. Call it with the translation log, record, and the original and new state objects. Use this when you want to save translated content as a draft rather than publishing directly.

Complete example

Here's a complete completion action that sets a specific author on all translated content:

1
import com.psddev.cms.db.Content;
2
import com.psddev.cms.ui.form.Note;
3
import com.psddev.dari.db.Recordable;
4
import com.psddev.translation.TranslationCompletionAction;
5
import com.psddev.translation.TranslationLog;
6
7
@Recordable.DisplayName("Publish with Translation Author")
8
public class TranslationAuthorCompletionAction extends TranslationCompletionAction {
9
10
@Note("Author selected here will be set as the content author for all translations")
11
private Author author;
12
13
@Override
14
protected void completeTranslation(Recordable newContent, TranslationLog log) {
15
newContent.as(HasAuthorData.class).setAuthor(author);
16
Content.Static.publish(
17
newContent,
18
log.getSite(),
19
newContent.as(Content.ObjectModification.class).getPublishUser());
20
}
21
22
// Placeholder interfaces for example compilation
23
public interface HasAuthorData {
24
void setAuthor(Author author);
25
}
26
27
public static class Author {
28
}
29
}

Configuration

Administrators configure completion actions in Admin > Sites & Settings under CMS > Translation > Type Settings. Each content type can have a different completion action configured.

See also