1. General Information

TranslationStudio uses workflows and specific scripts to send your translation requests to TranslationStudio.

Sometimes, you may wish to send specific content to TranslationStudio without any user input.

To do so, you can create your own custom script.

2. Preparations

You will need to have access to the TranslationStudio FSM jar file and add this as a dependency to your IDE.

This can be obtained from the FirstSpirit server or extracted from the FSM file.

3. Understanding the Script Mechanism

In this tutorial, we will try to send multiple pages to TranslationStudio which we assume to be known beforehand. A typical scenario would be to automatically translate a newly translated page into another langauge automatically upon successful import of translated content.

This is TranslationStudio’s script to allow for multiple page selection.

import com.idmedia.translationstudio.api.firstspirit.IClientWorkflowAPI;
import com.idmedia.translationstudio.api.firstspirit.IRegisterPageOperation;
import com.idmedia.translationstudio.api.firstspirit.ITranslationRequestMultiplePagesForm;
import com.idmedia.translationstudio.api.firstspirit.ITranslationWorkflowFormMultiplePages;
import com.idmedia.translationstudio.firstspirit.api.TranslationStudio;
import de.espirit.firstspirit.access.store.templatestore.WorkflowScriptContext;

/************************************************
 * TranslationStudio Script
 ************************************************/
WorkflowScriptContext wsc = (WorkflowScriptContext) context;

IClientWorkflowAPI pApi = TranslationStudio.get(wsc);
ITranslationWorkflowFormMultiplePages pForm = pApi.requestFormFactory().createMappingsFormPagesMultipleContextFree();

if (!pForm.showForm(true))
    wsc.doTransition("cancel");
else
{
    ITranslationRequestMultiplePagesForm p = pForm.getResult();
    if (p == null)
    {
        wsc.doTransition("cancel");
        return;
    }

    pApi.requestRegisterOperationFactory().requestRegisterPageOperation().register(p.getElements(), p, true);

    try
    {
        if (p.createPreviewPage())
            wsc.doTransition("success_preview");
        else
            wsc.doTransition("success_queued");
    }
    catch (e)
    {
        /* legacy */
        context.logError("Please check your workflow (transition) permissions. There seems to be a problem here.");

        if (p.createPreviewPage())
            new com.idmedia.translationstudio.client.workflow.ExecuteGenerationTaskOperation(wsc).perform("fts_preview");
        else
            new com.idmedia.translationstudio.client.workflow.ExecuteGenerationTaskOperation(wsc).perform("fts_queue");

        wsc.doTransition("cancel");
    }

}

In this example, the crucial lines of code are these

ITranslationRequestMultiplePagesForm p = pForm.getResult();
if (p == null)
{
    wsc.doTransition("cancel");
    return;
}

pApi.requestRegisterOperationFactory().requestRegisterPageOperation().register(p.getElements(), p, true);

The object p is an instance of the interface com.idmedia.translationstudio.api.firstspirit.ITranslationRequestMultiplePagesForm and will provide all necessary data of your translation request.

Now, the request data has to be stored in TranslationStudio’s FirstSpirit database (you access these in the data source area in SiteArchitect).

Adding the request data to the database is incredible simple and can be achieved easily:

ITranslationRequestMultiplePagesForm p = GET_DATA_FROM_SOMEWHERE();

IClientWorkflowAPI pApi = com.idmedia.translationstudio.firstspirit.api.TranslationStudio.get((WorkflowScriptContext) context);
pApi.requestRegisterOperationFactory().requestRegisterPageOperation().register(p.getElements(), p, true);

As you can see, you only have to consider 2 things:

  • You require a WorkflowScriptContext object to obtain TranslationStudio API access.

  • You have to provide an instance of the necessary TranslationStudio translation request data interface

At this point, you are able to store your own custom translation requests. The only thing necessary is to finally sending them to TranslationStudio.

The following code block will show you how this can be done - it is quite simple and only depends on whether or not you want to send preview pages or now:

if (p.createPreviewPage())
    new com.idmedia.translationstudio.client.workflow.ExecuteGenerationTaskOperation(wsc).perform("fts_preview");
else
    new com.idmedia.translationstudio.client.workflow.ExecuteGenerationTaskOperation(wsc).perform("fts_queue");

Congratulations, all you need to do now is to wrap it all up in a FirstSpirit script and add your JAR library to FirstSpirit (you can also just use the beanshell script).