Export OmegaT Project to HTML table

Here’s a script that lets you export your whole OmegaT project into an HTML file with one or more tables, one for each source file. The left column will have source segments, and the right will be either blank if the segment isn’t translated, or populated with translation (or , if translation was set to be empty). Each table will have source file name for its heading. The script was requested and kindly sponsored by Roman Mironov at Translation Agency Velior. As usual, in the below listing the heading is a link to pastebin.com where you can download this script.

  • write_table.groovy
    /* :name=       Write Table :description=Exports the project into HTML table
     * #Purpose:    Export the project into a HTML table
     * #Files:      Writes 'project_table.html' in the 'script_output' subfolder
     *              of current project's root. Each source file is exported to a separate
     *              table that has the name of the file as its heading, all source segments
     *              in the left column and corresponding target segments in the right.
     * #Details:    http://wp.me/p3fHEs-7L
     * @author:     Kos Ivantsov
     * @date:       2016-03-21
     * @version:    0.3
    def autoopen    = true
    def tagbg       = '#E5E4E2'   //tag background in context
    def tagfg       = 'green'     //tag foreground in context
    def contxtfg    = 'darkgray'  //font foreground in context
    def notebg      = 'yellow'    //note background
    def curtagbg    = '#BCC6DD'   //tag background in segment's text
    def curtagfg    = 'green'     //tag foreground in segment's text
    def curtxtbg    = '#BCC6CC'   //font background in segment's text
    def filenmbg    = 'lightgray' //cell background for filename
    def thbg        = 'gray'      //table heading cells background
    import static javax.swing.JOptionPane.*
    import static org.omegat.util.Platform.*
    import org.omegat.util.StaticUtils
    import org.omegat.util.StringUtil
    def prop = project.projectProperties
    if (!prop) {
        final def title = 'Export project to table'
        final def msg   = 'Please try again after you open a project.'
        showMessageDialog null, msg, title, INFORMATION_MESSAGE
    utils = (StringUtil.getMethods().toString().findAll("makeValidXML")) ? StringUtil : StaticUtils
    def folder = prop.projectRoot+'script_output/'
    projname = new File(prop.getProjectRoot()).getName()
    table_file = new File(folder + projname + '.html')
    // create folder if it doesn't exist
    if (! (new File (folder)).exists()) {
        (new File(folder)).mkdir()
    def painttag = {x, tbg, tfg -> x.replaceAll(/(\&lt\;\/?\s?\w+\s?\/?\d+?\s?\/?\s?\/?\&gt\;)/, /\<sup\>\<font size=\"1\"  style=\"background-color:$tbg\; color:$tfg" \>$1\<\/font\>\<\/sup\>/)}
    count = 0
    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
    <body>""", 'UTF-8')
    files = project.projectFiles
        for (i in 0 ..< files.size())
            fi = files[i]
      <table border=\"1px\" style=\"margin-bottom:50px\" width=\"100%\">
      <tr align=\"center\"><th style=\"border:1px solid black\" colspan=\"3\" width=\"100%\" bgcolor=lightgray><strong>$fi.filePath</strong></th></tr>\n""", 'UTF-8')
            for (j in 0 ..< fi.entries.size())
                def ignore = ''
                ste = fi.entries[j]
                source = ste.getSrcText()
                if (source ==~ /^(<\/?[a-z]+[0-9]* ?\/?>)+$/ ){
                ignore = 'yes'
                seg_num = ste.entryNum()
                target = project.getTranslationInfo(ste) ? project.getTranslationInfo(ste).translation : null;
                if (target == null)
                target = "zzznullzzz"
                if (target.size() == 0 )
                target = "<EMPTY>"
                source = utils.makeValidXML(source)
                source = painttag(source, curtagbg, tagfg)
                target = utils.makeValidXML(target).replaceAll(/zzznullzzz/, /⁠/)
                target = painttag(target, curtagbg, tagfg)
                if (ignore != 'yes'){
        <td style=\"border:1px solid black\" width=\"2%\">$seg_num</td>
        <td style=\"border:1px solid black\" width=\"49%\">$source</td>
        <td style=\"border:1px solid black\" width=\"49%\">$target</td>
      </tr>""", 'UTF-8')
            table_file.append("  </table>\n", 'UTF-8')
    table_file.append("</body>\n</html>", 'UTF-8')
    console.println "$count segments written to $table_file"
    if (autoopen == true) {
        def command
        switch (osType) {
            case [OsType.WIN64, OsType.WIN32]:
                command = "cmd /c start \"\" \"$table_file\"" // for WinNT
                // command = "command /c start \"\" \"$table_file\"" // for Win9x or WinME
            case [OsType.MAC64, OsType.MAC32]:
                command = ['open', table_file]
            default:  // for Linux or others
                command = ['xdg-open', table_file]

    The file will be saved as /script_output/project_table.html in the current project’s root, and will be rewritten each time the script is invoked. If there’s no script_output subfolder, it will be created by the script.

This is how the resultant file will look like (more or less, as here the theme’s .css kicks in with its own styles):

OmegaT User Interface Language Мова інтерфейсу користувача для OmegaT
User interface language for OmegaT Мова інтерфейсу користувача для OmegaT
If you want to use the same language in OmegaT as the one used during installation, check the box below. Якщо ви хочете, щоб в інтерфейсі OmegaT використовувалась та сама мова, що й під час інсталяції, поставте прапорець.
Otherwise, OmegaT will use the language of the operating system. В іншому випадку OmegaT буде використовувати мову операційної системи.
Use the installation language in OmegaT Використовувати мову інсталяції як мову інтерфейсу OmegaT
OmegaT-{0} OmegaT-{0}
OmegaT-{0}_{1} OmegaT-{0}_{1}
&OK &Добре
&Cancel &Відмінити
&Close &Закрити
&Filter &Фільтр
Re&move Filter Ви&лучити фільтр
Con&tents З&міст
&Back &Назад
&OK &Добре
Select Вибрати

If you find it helpful or have ideas how to improve it, drop a note. But as of now,

Good luck!


4 thoughts on “Export OmegaT Project to HTML table

  1. This plugin is a life-saver. and should be in the official repo. Unfortunately it seems that it stopped working on the new 4.1.2 version. Any hints?

    “An error occurred
    javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: static org.omegat.util.StaticUtils.makeValidXML() is applicable for argument types: (java.lang.String) values: [ommited]”

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s