Magnolia 5.4 reached end of life on November 15, 2018. This branch is no longer supported, see End-of-life policy.

Page tree
Skip to end of metadata
Go to start of metadata

The Extend CTS Auto Translation Module allows you to automatically translate content using Google Translate or Microsoft Translator.

The module connects both external APIs with Magnolia enabling automatic machine-translation with a single click.

You can enable automatic translation in any content app. The CTS Demo module enables automatic translation in the Tour Categories app

Installing

Maven is the easiest way to install the module. Add the following dependency to your bundle:

<dependency>
  <groupId>info.magnolia</groupId>
  <artifactId>magnolia-module-content-translation-support-extend-auto-translation</artifactId>
  <version>1.7.1</version>
</dependency>

Pre-built jars are also available for download. See Installing a module for help.

Configuration

The module is configured in /modules/content-translation-support-extend-auto-translation.

Node name

 modules

 content-translation-support-extend-auto-translation

 dialogs

 commands

How auto translation works

The CTS Demo module enables automatic translation in the Tour Categories app

To automatically translate content:

  1. Enable automatic translation in a content app. 
  2. Make sure you have additional content languages configured and that the fields in the detail subapp that you want to translate have an i18n property set to true. See Enabling multilanguage content for more.
  3. Click Automatic translate.
     
  4. In the Translation request dialog:
    1. Select target languages.
    2. Select translator.
    3. Optionally, add a comment.
    4. Click Translate.
       
  5. You will receive a message in the Pulse when the translation is complete.
  6. Edit the item to see the translated content. 
     

Auto translation translators

The module includes two default translator implementations that integrate external translation services:  

Translators are configured in the CTS Common module in /modules/content-translation-support-extend-common/config/translators.

Node nameValue

 content-translation-support-extend-auto-translation-common

 

 config

 

 translators

 

 Google

 

 config

 

 clientCode

AIzaSyAsOSIL1-sEtF9gBB7eJEWlatS_HQdoTTc

 clientId

MagnoliaDemo1

 class

info.magnolia.module.contenttranslationsupport.extend.autotranslation.translator.GoogleTranslator

 identifier

Google

 name

Google.com

 Microsoft

 

 config

 

 clientCode

lOSN0hgDEwpsjpd//RLv44UrmUIK+KZtEKesF2CxpTs=

 clientId

magnolia_module_cts_workflow_autotranslations

 class

info.magnolia.module.contenttranslationsupport.extend.autotranslation.translator.MicrosoftTranslator

 identifier

Microsoft

 name

Microsoft.com

Properties:

<translator name>

required

Name of translator.

config

required

Configuration node.

clientCode

required

  • Google: API key.
  • Microsoft: Client secret code.

clientId

required

  • Google: Google username.
  • Microsoft: Client Id.

class

required

  • GoogleTranslator implements Translator for Google.
  • MicrosoftTranslator implements Translator for Microsoft.

identifier

required

Translator identifier.

name

required

Translator name.

Auto translate command

The module registers one command: autoTranslateCommand that chains four commands that are executed sequentially as a single command. The command is used for the commit action in the Translation request dialog. The command classes are part of the CTS Common module. 

The command is registered in /modules/content-translation-support-extend-auto-translation/commands/autoTranslation.

Node nameValue

 commands

 

 autoTranslation

 

 autoTranslateCommand

 

 exportCommand

 

 class

info.magnolia.module.contenttranslationsupport.extend.common.command.ExportTranslationCommand

 translateCommand

 

 class

info.magnolia.module.contenttranslationsupport.extend.common.command.TranslateCommand

 trackingCommand

 

 class

info.magnolia.module.contenttranslationsupport.extend.common.command.TranslationTrackingCommand

 importCommand

 

 class

info.magnolia.module.contenttranslationsupport.extend.common.command.ImportTranslationCommand

Properties:

commands

optional

Commands folder

autotranslation

required

Auto translation catalog.

autoTranslateCommand

required

Main command name.

<chained command names>

required

Chained command node names. One for each command in the chain. The child commands are executed one-by-one in the node order from top down.

class

required

  1. ExportTranslationCommand converts translatable content into XLIFF format.
  2. TranslateCommand calls the translation service to translate the content with the selected translator.
  3. TranslationTrackingCommand tracks the translation progress.
  4. ImportTranslationCommand Imports the translated content (in XLIFF format) back into the workspace.

Translation request dialog

The Translation request dialog opens when the Automatic translate action is executed.

 In addition to standard fields and actions, the dialog uses the custom auto translate command, translate dialog action definition class and languages select field.

The dialog is configured in /modules/content-translation-support-extend-auto-translation/dialogs/autoTranslationRequest.

Node nameValue

 dialogs

 

 autoTranslationRequest

 

 actions

 

 commit

 

 asynchronous

true

 catalog

autoTranslation

 class

info.magnolia.module.contenttranslationsupport.extend.common.action.TranslateDialogCommandActionDefinition

 command

autoTranslateCommand

 label

Translate

 cancel

 

 form

 

 tabs

 

 translation

 

 fields

 

 repository

 

 path

 

 uuid

 

 username

 

 sourceLangDisplay

 

 targetLangs

 

 class

info.magnolia.module.contenttranslationsupport.extend.common.field.LanguagesSelectFieldDefinition

 label

Target languages

 leftColumnCaption

Configured languages

 required

true

 rightColumnCaption

Selected languages

 translator

 

 comment

 

 label

Translation request

Properties:

autoTranslationRequest

required

Dialog name.

actions

required

Actions node.

<action name>

required

  • commit: TranslateDialogCommandActionDefinition calls autoTranslateCommand that calls the external service and then imports the translated content.
  • cancel: Standard cancel dialog action definition

form

required

Form node.

tabs

required

Tabs node.

translation

required

Translation tab.

fields

required

Fields node.

<field name>

required

  • repository, path, uuid, userName, sourceLangDisplay are read only text fields.
  • targetLangs uses the custom LanguagesSelectFieldDefinition class that automatically displays configured languages for selection.
  • translator is a select field that makes the configured translators available for selection.
  • comment is a text field.

Here's the Translation request dialog.

Enabling automatic translation in content apps

You can enable automatic content translation in any content app.

Example: Enabling automatic translation in the Contacts app

  1. Add the i18n property to any field you want to translate in the detail subapp. See Enabling mulitlanguage content for more.
    Example: New Bio text field in the Personal tab in /modules/contacts/apps/contacts/subapps/detail/editor/form/tabs/personal/fields/bio.

    Node nameValue

     editor

     

     form

     

     tabs

     

     personal

     

     fields

     

     bio

     

     class

    info.magnolia.ui.form.field.definition.TextFieldDefinition

     i18n

     true

     label

    Bio

     rows

    3
  2. Add the Automatic translate action to the browser supapp. The CTS Demo module adds the Automatic translate action to the Tour Categories app. You can copy the action configuration from there. 
    ExampleautomaticTranslateAction in /modules/contacts/apps/contacts/subApps/browser/actions/automaticTranslateAction.

    Node nameValue

     browser

     

     actions

     

     automaticTranslateAction

     

     availability

     

     nodes

    true

     root

    true

     class

    info.magnolia.module.contenttranslationsupport.extend.common.action.OpenTranslateDialogActionDefinition

     dialogName

    content-translation-support-extend-auto-translation:autoTranslationRequest

     icon

    icon-content-translation-app

     label

    Automatic translate
  3. Add the action to the action bar. 
    ExampleautomaticTranslateAction in /modules/contacts/apps/contacts/subApps/browser/actionbar/sections/contact/groups/importExportActions/items/automaticTranslateAction.

    Node name

     browser

     actionbar

     sections

     contacts

     groups

     importExportActions

     items

     export 

     automaticTranslateAction 

  4. Test the action in the app. 
    ExampleAutomatic translate action and dialog in the Contacts app.