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 * * THIS SCRIPT HAS BEEN SPONSORED BY TRANSLATION AGENCY VELIOR [ http://velior.ru ] * * #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 return } 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(/(\<\;\/?\s?\w+\s?\/?\d+?\s?\/?\s?\/?\>\;)/, /\<sup\>\<font size=\"1\" style=\"background-color:$tbg\; color:$tfg" \>$1\<\/font\>\<\/sup\>/)} count = 0 table_file.write("""\ <html>\n<head> <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_file.append("""\ <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'){ table_file.append("""\ <tr> <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') count++ } } 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 break case [OsType.MAC64, OsType.MAC32]: command = ['open', table_file] break default: // for Linux or others command = ['xdg-open', table_file] break } command.execute() } return
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 noscript_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_3.0.2_L10N_Full/release/win32-specific/CustomMessages.ini | |
---|---|
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_3.0.2_L10N_Full/src/org/omegat/Bundle.properties | |
---|---|
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!
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]”
sure, grab this file: https://sourceforge.net/projects/omegatscripts/files/write%20scripts/write_table.groovy/download
it should work in both 3.x and 4.x
I updated the post, now it links to the SF.net repo
Thank you so much, Kos. Great work! Both segment numbers and displaying tags in small fonts are also great ideas.