Did you find this page useful? Give us feedback.
Did you find the information
on this page useful?

Yes
Somewhat
No
  Tell us more about your choice:
Missing information
Incorrect information
Misleading information
I have a question
Other
  Enter your comment in the box below.
If you need assistance, please contact Support instead.

  Type the letters
simple PHP captcha
 

This topic is only for advanced users, knowing scripts and being able to create scripts.

Note: If you use a memoQ server, please read the memoQ server installation guide for setting up automated scripting for online projects, chapter 5.1.2. This guide is available at the Kilgray website.

Specify automated pre- and post-processing actions for your documents before you import them into your memoQ project and after exporting them from your memoQ project.

Kilgray provides you with some executables which need to be installed separately in the scripting folder root. Download the scripts from the Download section > Tools and utilities of the Kilgray website.

Available scripts:

Converting URL-encoded content in XML files to Unicode before import, and back to URL-encoded after export

Tweaking code page, Unicode encoding, or presence/absence of BOM (all text bases file formats)

Mapping language codes without country codes (en) to ones with country codes (en-us) in XML. This is needed by some CMS systems.

You can also create your own scripts for example to replace country-specific language codes in XML files with non-country specific codes (or vice versa). Another use case can be that you have to deal with webshop databases to translate: you receive a CSV which you can transform into an HTML file that references URLs of images of articles. This way you get a preview of the webshop article in memoQ.

How to begin

The import and export actions can be set up just like other project automation actions. On the Quick Access Toolbar, click the Resource console icon (or click the memoQ ribbon tab, then click Resources > Resource Console). In the Resource Console, click the Project templates icon. Click the Create new link to create a new template. Or select a template, then click Clone to clone (make a copy) of the selected template and then make adjustments to it. Or select a template, and then click the Edit link to edit the template.

After you opened a template, go to the automated actions of the Edit project template dialog. Click the Script before import tab:

Options

In the Script and file types section, enter a file extension in the Wildcard expression field, e.g. *.exe. *.* indicates all file types. All wildcard expressions that are supported by the Windows Shell are possible. The file type will then appear in the Script and input files list. Add a new expression, and then click Add as new item. Or select an item, then make modifications and click Update. The Script name field is automatically filled in when you start adding files in the below section.

Click the Add files… button in the Settings for selected script section. You can select multiple files: executable files and zero or more related files (e.g. EXE and several DLLs or a BAT file that in turn calls other files). To remove a file, select a file in the added files list, and then click Delete to remove it.

Select an item from the Select the files needed to run your code list box, click the Set as command button. The selected item will be the command which memoQ will invoke. The name of the command will be copied to the Command name field. The command name field is editable. If the command name field already contained a name, then this name will be overwritten if you select another item from the list and set it as command.

You can also specify a command line argument. Click in the Command line arguments field, then click the Insert placeholder link. Select a placeholder: inputfilename, srclangiso2, srclangiso3, trglanglistiso2 or trglanglistiso3. You can also combine placeholders. Read more on command line arguments here.

The Full command field will reflect your selection: Command name followed by the Command line arguments.

The following parameters are passed on to the custom code:

Input file name (%inputfilename)

Source language (%sourcelanguage)

Target language list (%targetlanguagelist)

Note: The target language list is only used for import scripts.

In the Timeout section, you can specify the timeout in seconds. The default is 5 seconds. The upper limit of the timeout is determined on the server at installation. The timeout is always specified for an individual script, not for the project. For example you want to run 3 scripts before import, these scripts can then have 3 different timeout values.

Click the Test run my command button to test that your chosen parameters for the executables are set up correctly.

You can browse to one input file (click the Browse button). You cannot select multiple files. Click OK to run the test. The source and target languages are taken from the project template. If you have not configured language parameters, memoQ will display a dialog to define them.

Note: Since the project is not yet created, memoQ will create a temporary folder (your locally configured Temp folder, using the template's name instead of the project name for the folder name). This temporary folder will be automatically deleted when you leave the Specify custom code details dialog.

Define the script to run after document export. Click the Script after export tab. The options are similar to the Script before import options.

Specifying custom code execution in your project template

When you click the Project automation tab, you have available triggers. Select a trigger such as After document import or Before reimport or After project wrap-up. Then click the Settings button to invoke the actions for the selected trigger. Note that you can set a scope for triggers which can be for documents only or for the whole project. You will find an item Execute custom code.

After you selected the Execute custom code action, click Add. The Specify custom code details dialog appears:

The options are the same as on the Scripts before import and Scripts after export tabs, but you have more options for placeholders:

%assignedto

%deadline (this is the deadline for the person who is currently assigned to the document, no the final deadline)

%finaldeadline (final deadline)

%workflowstatus

%user (user who launched the trigger)

%target language (this parameter is used for non-import scripts, the action can be triggered e.g. when one translator delivers for one target language)

Note: User names are represented by user account names. Time placeholders are substituted as an ISO 8601 standard time format. Timestamps have UTC time format. The workflow status is passed on as a string and the possible values are passed on too.

Note: The required output file's name as a parameter to the custom code, using a placeholder named {outputfilepath}.

In addition, there are 2 check boxes below the Timeout section:

Export documents as MQXLIFF for script to process check box: Check this check box to export each document in the trigger's scope as MQXLIFF and to pass these documents to the custom code. MQXLIFF is memoQ's bilingual XLIFF format.

Update documents in project from script's output check box: Check this check box to tell memoQ that the custom code execution will produce output files that need to be imported back via Update bilingual.

Running the code in a project

When you create a local memoQ project from a template, and your template contains custom code, then memoQ creates a project scripting subfolder under the scripting root folder (which is under C:\ProgramData\memoQ). When you install memoQ 2015, the scripting root folder is automatically created. memoQ then copies all the files to the scripting code subfolder.

When you create an online project, then the project's folder and subfolders in the scripting root are created. Actions with EXE files will be skipped if the custom code execution is allowed on the server; it is limited to batch only. The publish project operation works the same way as in projects without custom code customization in templates.

What happens when custom code execution is triggered for import

When you trigger an import or export script, memoQ copies all the input files to the working directory of the custom code, renaming them with a GUID if necessary. If no error occurs, the import proceeds as normal. In case of export scripts, export already happened (in case of no files, memoQ logs a message to the log file). After copying the input files, memoQ calls the custom code with the parameters and command line arguments you defined in the template (one by one for each file).

The output files have the _out appended to the file names. If a file name is matched by multiple wildcards, all actions which match are executed – in the order they are specified in the template.

What happens when custom code execution is triggered for export

After you triggered the custom code to run, memoQ exports bilingual files for the scope of the trigger (if specified in the template). These files are exported to the working directory of the custom code. memoQ then invokes the custom code for each file with the parameters and command line arguments specified in the template. If your template specifies a bilingual file update, then memoQ executes the bilingual file update with the output file. If the output file is missing, memoQ will display an error message.

Once there are no more input files left, memoQ does the following:

Takes the custom code result as the input for whatever next step you specified in the workflow.

Deletes the input and output files for this particular invocation of the custom code. All temporary files are removed.

For memoQWeb: If you start a template based project in memoQWeb, then the automation runs as in an online project. However, the automation can only be set up in templates which are available in the Resource Console in the memoQ desktop application.

Publishing a local project to your memoQ server: If you have a local project where you run some custom code, then your custom code may invoke other programs that memoQ does not know about (e.g. a runtime environment) or may reference to another program by its absolute path on your computer. It may happen that this custom code will not work after you published your local project (transformed it into an online project).

Timeout during post-processing: If a process does not return within the specified timeout, memoQ aborts the process and writes an entry in the log file. If you work in an online project, an alert on the timeout is generated (failed automation task). When the custom code is stopped due to a timeout, the import or export will fail (equivalent to an automation failure). If output files are only generated partly, memoQ will not replace them or generate output files at all when a timeout happens or an automated task fails.

What the custom code execution cannot do

If you use runtime environments such as Java, you need to install these programs separately.

All paths in the executable need to be defined as relative paths to the working folder and the output folder of the executable.

Large executables in local projects may produce large sized templates.

One input file always needs to correspond to one output file.

The custom code does not change the file type and file extension.

After the custom code was executed, it deletes all temporary files.

The custom code cannot process files pre-import and post-export differently based on target language. memoQ only passes on the list of target languages.

Workflow statuses are passed on as strings, users are represented by their user account name and the UTC time format is used.

Compatibility note: If you have an older memoQ server, but the latest memoQ desktop version: the project template in the memoQ desktop application contains automation. The older memoQ server is not able to execute these automations. You can move on to create your project, but no custom code execution will work.