OmegaT Live preview (based on LibreOffice)

Below you’ll find a quick and dirty live preview solution for OmegaT on GNU/Linux.

In order for it to work, you’ll need any command line converter to convert your target files to PDF, and any PDF viewer to view the converted file. In the solution provided here Zathura PDF viewer is used. It is a very lightweight, keyboard-driven (albeit with vi-like keybindings) application that can invert document colors using a custom color scheme, and, most importantly, it reloads documents as they are changed, but keeps the previously open position, which makes it ideal for live previewing. Target files are converted using LibreOffice since I had it installed anyway; but any other command line tool that converts to PDF would do.

First of all, we’ll need a bash script which will glue our components together to produce the PDF for preview. You can either download it from GitHub or copy the code from here:

if [ ! -d "$PDFDIR" ]; then
    mkdir "$PDFDIR"
mv "$(basename "$FILENAME")" "current."${FILENAME##*.}""  
lowriter --convert-to pdf --outdir $PDFDIR $PDFDIR/current.${FILENAME##*.} > /dev/null 2>&1
ps ux|grep zathura|grep current.pdf > /tmp/omt.txt
if [ -z "$(ps ux|grep $PDFVIEWER|grep current.pdf)" ]; then
    $PDFVIEWER $PDFDIR/current.pdf > /dev/null 2>&1 &
    echo "Previewing current target file"

This file should be saved somewhere handy and made executable. Next, this script should be called by OmegaT each time the target files are created, i.e. through its post-processing command. To do so, open Preferences dialog, select Saving and Output, and enter in the input area in the center of the window:

/path/to/ ${targetRoot}${fileShortPath} ${fileName} ${projectRoot}

Like this:

Of course, you need to specify your path to the script, as it most likely won’t be /opt/omegat/extra/

If you’ll need it only in certain projects, it can be stored in the project folder, in omegat subfolder, for instance. You’ll need to enable per-project external commands in the dialog above, like this:

And then in the project options (Ctrl+E) add this line to the field External Post-processing Command:

${projectRoot}/omegat/ ${targetRoot}${fileShortPath} ${fileName} ${projectRoot}

Like this:

This time there’s no need to specify the whole path, as OmegaT will substitute ${projectRoot} variable for the actual project’s path.

DISCLAIMER: This script doesn’t handle any errors which might arise due to unsupported file types, or permissions, or invalid target files etc. It’s very unlikely that it can cause any serious problem, but if you don’t get the preview, you’ll need to investigate it yourself. For now it only works on GNU/Linux. If anyone is willing to adjust it to run on other platforms, I’ll be happy to post your findings (if you want them posted here, of course).

WARNING: If your file names contain spaces, you’ll need to wrap OmegaT variables in doublequotes, like so:

/path/to/ "${targetRoot}${fileShortPath}" "${fileName}" "${projectRoot}

One thought on “OmegaT Live preview (based on LibreOffice)

  1. Thank you very much for the idea. For Windows users with Word installed, here is my solution. It works like charm.

    Use Sumatra PDF and to convert directly using Word (if it is locally installed).
    Create a macro directly in the Word (in the normal or any startup template) and call Word with command line arguments to convert the file.

    The command needed is ‘(path_to_word)WINWORD.EXE’ /mExporttoPDF /q ‘FullTargetFilename’

    Sub ExportToPDF()
    ChangeFileOpenDirectory ActiveDocument.Path
    ActiveDocument.ExportAsFixedFormat _
    OutputFileName:=Left(ActiveDocument.FullName, InStrRev(ActiveDocument.FullName, “.”)) + “pdf”, _
    ExportFormat:=wdExportFormatPDF, _
    OpenAfterExport:=False, _
    OptimizeFor:=wdExportOptimizeForPrint, _
    Range:=wdExportAllDocument, _
    From:=1, _
    To:=1, _
    Item:=wdExportDocumentContent, _
    IncludeDocProps:=True, _
    KeepIRM:=True, _
    CreateBookmarks:=wdExportCreateNoBookmarks, _
    DocStructureTags:=True, _
    BitmapMissingFonts:=True, _
    Application.Quit SaveChanges:=wdDoNotSaveChanges
    End Sub

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s