Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 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: 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
- return
- }
- 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
- 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=\"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/, /⁠/)
- table_file.append("""\
- <tr><td style=\"border:1px solid black\" width=\"50%\">$source</td>
- <td style=\"border:1px solid black\" width=\"50%\">$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"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement