Advertisement
KosIvantsov

write_source2file.groovy

Jul 15th, 2013
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 1.66 KB | None | 0 0
  1. /*
  2.  * #Purpose:  Write all source segments to a file
  3.  * #Files:    Writes 'allsource.txt' in the current project's root
  4.  *
  5.  * @author:  Kos Ivantsov
  6.  * @date:    2013-07-16
  7.  * @version: 0.2
  8.  */
  9.  
  10. /* change "includefilenames" to anything but 'yes' (with quotes)
  11.  * if you don't need filenames to be included in the file */
  12.  
  13. def includefilenames = 'yes'
  14.  
  15. import static javax.swing.JOptionPane.*
  16. import static org.omegat.util.Platform.*
  17.  
  18. // abort if a project is not opened yet
  19. def prop = project.projectProperties
  20. if (!prop) {
  21.     final def title = 'Source to File'
  22.     final def msg   = 'Please try again after you open a project.'
  23.     showMessageDialog null, msg, title, INFORMATION_MESSAGE
  24.     return
  25. }
  26.  
  27. def fileloc = prop.projectRoot+'/allsource.txt'
  28. writefile = new File(fileloc)
  29.  
  30. writefile.write("", 'UTF-8')
  31. def count = 0
  32.  
  33. if (includefilenames == 'yes') {
  34.     files = project.projectFiles;
  35.     for (i in 0 ..< files.size())
  36.     {
  37.         fi = files[i];
  38.         marker = "+${'='*fi.filePath.size()}+\n"
  39.         writefile.append("$marker|$fi.filePath|\n$marker", 'UTF-8')
  40.         for (j in 0 ..< fi.entries.size())
  41.         {
  42.         ste = fi.entries[j];
  43.         source = ste.getSrcText();
  44.         writefile.append source +"\n", 'UTF-8'
  45.         count++;
  46.         }
  47.     }
  48. } else {
  49.     project.allEntries.each { ste ->
  50.     source = ste.getSrcText();
  51.     writefile.append source+"\n",'UTF-8'
  52.     count++}
  53.     }
  54.  
  55. console.println count +" segments written to "+ writefile
  56. final def title = 'Source to File'
  57. final def msg   = count +" segments"+"\n"+"written to \n"+ writefile
  58. showMessageDialog null, msg, title, INFORMATION_MESSAGE
  59. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement