Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Substitute with template
- *
- * @author Kos Ivantsov
- * @date 2013-06-20
- * @version 0.1
- */
- import static javax.swing.JOptionPane.*
- import static org.omegat.util.Platform.*
- def prop = project.projectProperties
- if (!prop) {
- final def title = 'Replace using substitution file'
- final def msg = 'Please try again after you open a project.'
- showMessageDialog null, msg, title, INFORMATION_MESSAGE
- return
- }
- def folder = prop.projectRoot
- def fileloc = folder+'/subst_template.txt'
- subst_file = new File(fileloc)
- if (! subst_file.exists()) {
- final def title = 'No file' ;
- final def msg = 'Substitution file ' + subst_file + ' doesn\'t exist.' ;
- showMessageDialog null, msg, title, INFORMATION_MESSAGE ;
- return
- }
- length = subst_file.readLines().size() ;
- search_array = []
- replace_array = []
- def count = 0 ;
- while ( count < length ) {
- ln = subst_file.readLines().get(count).tokenize('\t')
- sr = ln[0]
- rp = ln[1]
- search_array.add(sr)
- replace_array.add(rp)
- count++ ;
- }
- def range = 0..(search_array.size() - 1)
- /*
- * The script can either use source text, replacing the target after all
- * substitutions, or it can use the text that is already placed as translation,
- * replacing it with itself after substituting
- * To enable desired behaviour, use one of the two following lines (be
- * sure to have the other commented out)
- */
- //target = editor.currentEntry.getSrcText();
- target = editor.getCurrentTranslation()
- for ( i in range) {
- target = (target =~ search_array[i] ).replaceAll( replace_array[i] )
- }
- editor.replaceEditText(target);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement