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 <EMPTY>, 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
     * #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:	2013-10-10
     * @version:	0.1
    import static javax.swing.JOptionPane.*
    import static org.omegat.util.Platform.*
    import org.omegat.util.StaticUtils
    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
    def folder = prop.projectRoot+'script_output/'
    table_file = new File(folder+'project_table.html')
    // create folder if it doesn't exist
    if (! (new File (folder)).exists()) {
    	(new File(folder)).mkdir()
    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=\"2\" width=\"100%\" bgcolor=lightgray><strong>$fi.filePath</strong></th></tr>\n""", 'UTF-8')
    		for (j in 0 ..< fi.entries.size())
    			ste = fi.entries[j]
    			source = ste.getSrcText()
    			target = project.getTranslationInfo(ste) ? project.getTranslationInfo(ste).translation : null;
    			if (target == null)
    			target = "zzznullzzz"
    			if (target.size() == 0 )
    			target = "<EMPTY>"
    			source = StaticUtils.makeValidXML(source)
    			target = StaticUtils.makeValidXML(target).replaceAll(/zzznullzzz/, /⁠/)
      <tr><td style=\"border:1px solid black\" width=\"50%\">$source</td>
      <td style=\"border:1px solid black\" width=\"50%\">$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"

    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!


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