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")2public abstract class TranslationAuthorCompletionAction extends TranslationCompletionAction {3// Implementation4}
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")2public abstract class TranslationAuthorCompletionActionWithFields extends TranslationCompletionAction {34@Note("Author selected here will be set as the content author for all translations")5private 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@Override2protected void completeTranslation(Recordable newContent, TranslationLog log) {3// Apply custom logic to the translated content4newContent.as(HasAuthorData.class).setAuthor(author);56// Save the content (required)7Content.Static.publish(8newContent,9log.getSite(),10newContent.as(Content.ObjectModification.class).getPublishUser());11}
Method parameters
| Parameter | Description |
|---|---|
newContent | The translated content object |
log | Information 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:
1import com.psddev.cms.db.Content;2import com.psddev.cms.ui.form.Note;3import com.psddev.dari.db.Recordable;4import com.psddev.translation.TranslationCompletionAction;5import com.psddev.translation.TranslationLog;67@Recordable.DisplayName("Publish with Translation Author")8public class TranslationAuthorCompletionAction extends TranslationCompletionAction {910@Note("Author selected here will be set as the content author for all translations")11private Author author;1213@Override14protected void completeTranslation(Recordable newContent, TranslationLog log) {15newContent.as(HasAuthorData.class).setAuthor(author);16Content.Static.publish(17newContent,18log.getSite(),19newContent.as(Content.ObjectModification.class).getPublishUser());20}2122// Placeholder interfaces for example compilation23public interface HasAuthorData {24void setAuthor(Author author);25}2627public 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
- Translation Services — Building custom translation integrations
- Translation Actions — Adding custom UI elements