#OmegaT target statistics

This post is about a quick and dirty hack that allows to get target statistics for OmegaT current project. Continue reading

Advertisements

Stripping Tags Everywhere, Groovy Way

Every once in a while you have to deal with a match that has wrong tags. Hopefully, pretty soon OmegaT will be smart enough to deal with such matches for you, making it possible to insert a wrongly tagged match in such a way that you wouldn’t have to fix tags — they’ll get fixed on their own. But while we are not there yet, a practical workaround is to use the match tag-free and to insert proper tags wherever needed (OmegaT 3 lets you insert them one by one, and a new default shortcut for that is Ctrl+T).
In this post I share 5 groovy scripts to strip tags in different situations (headings link to pastebin.com, files can be downloaded from there):

  • Replacing target with match
    /*
     * #Purpose: Replace current target with tag-free match 
     * #Details: http: // wp.me/p3fHEs-4W
     * 
     * @author   Kos Ivantsov
     * @date     2013-06-26
     * @version  0.1
     */
    
    import static javax.swing.JOptionPane.*
    import static org.omegat.util.Platform.*
    import org.omegat.core.Core;
    
    // abort if a project is not opened yet
    def prop = project.projectProperties
    if (!prop) {
      final def title = 'Replace with Match (no tags)'
      final def msg   = 'Please try again after you open a project.'
      showMessageDialog null, msg, title, INFORMATION_MESSAGE
      return
    }
    
    def match = Core.getMatcher()
    def near = match.getActiveMatch()
    if (near != null) {
      def matchtranslation = "$near.translation"
      matchtranslation = matchtranslation.replaceAll(/<\/?[a-z]+[0-9]* ?\/?>/, '')
      editor.replaceEditText(matchtranslation);
    }
    
  • Inserting match
    /*
     * #Purpose: Insert tag-free match into current target 
     * #Details: http: // wp.me/p3fHEs-4W
     * 
     * @author   Kos Ivantsov
     * @date     2013-06-26
     * @version  0.1
     */
    
    import static javax.swing.JOptionPane.*
    import static org.omegat.util.Platform.*
    import org.omegat.core.Core;
    
    // abort if a project is not opened yet
    def prop = project.projectProperties
    if (!prop) {
      final def title = 'Insert Match (no tags)'
      final def msg   = 'Please try again after you open a project.'
      showMessageDialog null, msg, title, INFORMATION_MESSAGE
      return
    }
    
    def match = Core.getMatcher()
    def near = match.getActiveMatch()
    if (near != null) {
      def matchtranslation = "$near.translation"
      matchtranslation = matchtranslation.replaceAll(/<\/?[a-z]+[0-9]* ?\/?>/, '')
      editor.insertText(matchtranslation)
    }
    
  • Replacing target with source
    /*
     * #Purpose: Replace current target with tag-free source 
     * #Details: http: // wp.me/p3fHEs-4W
     * 
     * @author   Kos Ivantsov
     * @date     2013-06-26
     * @version  0.1
     */
    
    import static javax.swing.JOptionPane.*
    import static org.omegat.util.Platform.*
    
    // abort if a project is not opened yet
    def prop = project.projectProperties
    if (!prop) {
      final def title = 'Replace with Source (no tags)'
      final def msg   = 'Please try again after you open a project.'
      showMessageDialog null, msg, title, INFORMATION_MESSAGE
      return
    }
    
    def stext = editor.currentEntry.getSrcText().replaceAll(/<\/?[a-z]+[0-9]* ?\/?>/, '')
    editor.replaceEditText(stext)
    
  • Inserting source
    /*
     * #Purpose: Insert tag-free source into current target 
     * #Details: http: // wp.me/p3fHEs-4W
     * 
     * @author   Kos Ivantsov
     * @date     2013-06-26
     * @version  0.1
     */
    
    import static javax.swing.JOptionPane.*
    import static org.omegat.util.Platform.*
    
    // abort if a project is not opened yet
    def prop = project.projectProperties
    if (!prop) {
      final def title = 'Insert source (no tags)'
      final def msg   = 'Please try again after you open a project.'
      showMessageDialog null, msg, title, INFORMATION_MESSAGE
      return
    }
    
    def stext = editor.currentEntry.getSrcText().replaceAll(/<\/?[a-z]+[0-9]* ?\/?>/, '')
    editor.insertText(stext)
    
  • Stripping tags in target
    /*
     * #Purpose: Remove tags in the current target 
     * #Details: http: // wp.me/p3fHEs-4W
     * 
     * @author   Kos Ivantsov
     * @date     2013-06-26
     * @version  0.1
     */
    import static javax.swing.JOptionPane.*
    import static org.omegat.util.Platform.*
    
    // abort if a project is not opened yet
    def prop = project.projectProperties
    if (!prop) {
      final def title = 'Strip tags in current segment'
      final def msg   = 'Please try again after you open a project.'
      showMessageDialog null, msg, title, INFORMATION_MESSAGE
      return
    }
    
    target = editor.getCurrentTranslation()
    if (target != null) {
    target = target.replaceAll(/<\/?[a-z]+[0-9]* ?\/?>/, '')
    }
    editor.replaceEditText(target)
    

There are plenty of other ways to remove tags in OmegaT, some of them even posted as my recipes, but the beauty of using groovy is that scripts can be run from withing OmegaT, with its own keyboard shortcut, without needing to assign an OS shortcut to an external script/application.
As usual, inspiration for the scripts was an idea shared at OmegaT Yahoo! Group


Good luck!

OmegaT match insert/replace without tags

Situation

After having translated a complete user manual that you converted from PDF to ODT to be able to work on it in OmegaT, you receive another manual from the same client, but this time it’s a DOCX file. Great! You can start right away, without converting anything. That should be a peace of cake — half of the manual looks almost the same as the one you have just done.

Problem

After starting to work with it you find out that getting a lot of 95-97% would be really awesome, if it wasn’t for all those nasty tags that are very different in the source and in the match. And there is no “Insert match without tags” menu item in OmegaT (yet).

Continue reading