Appendix F. Scripting plugin
Prev |  | Next

# Appendix F. Scripting plugin

## 1. Introduction

OmegaT-Scripting allows to run scripts written in different scripting languages in OmegaT.

## 2. Installation and Use

The Scripting plugin for OmegaT can be downloaded from the OmegaT plugins download site. Unzip the files, and put them all in the "plugins" folder located in OmegaT installation folder, that is the folder that contains the OmegaT.jar. Create the "plugins" folder first, if it does not exist.

This adds a new submenu Tools > Scripting. Below the Scripting submenu , there's 12 place holders available for scripts. Clicking Scripting opens the Scripting dialog:

The Scripting dialog allows you to load an existing script into the text area and run it against the current opened project. To customize the script feature, do the following:

- Load a script into the editor by clicking on its name in the list on the left panel.

- Right-click on a button from "<1>" to "<12>" in the bottom panel and select "Add". In the above example, two scripts (position 1 and 2) have already been added.

- When you left-click on the number, the selected script will run. You can start the selected macros from the main menu as well by using their entries in the Tools menu or by pressing Ctrl+Alt+F# (# 1 to 12).

The following scripting languages have been implemented:

- NetRexx (http://www.netrexx.org/): it supports a classic REXX syntax, with no reserved keywords, along with considerable additions to support object-oriented programming in a manner compatible with Java's object model. All existing Java class libraries can be used unchanged and without special setup; at the same time, a Java programmer can opt to just use the Rexx class from the runtime package for improved string handling in Java syntax source programs.

- XSLT (Extensible Stylesheet Language Transformations): is a declarative, XML-based language used for the transformation of XML documents. The original document is not changed; rather, a new document is created based on the content of an existing one. The new document may be serialized (output) by the processor in standard XML syntax or in another format, such as HTML or plain text. XSLT is most often used to convert data between different XML schemas or to convert XML data into web pages or PDF documents.

- Groovy (http://groovy.codehaus.org): is a dynamic language for the Java Virtual machine. It builds upon the strengths of Java but has additional power features inspired by languages like Python, Ruby and Smalltalk.

- JavaScript (sometimes abbreviated JS, not to be confused with Java): is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm language, supporting object-oriented, imperative, and functional programming styles. Being the language behind popular software such as Firefox it is a familiar and preferred programming tool in the open-source domain.

All the languages have access to the OmegaT object model, with the project as the top object. The following code snippet in groovy for instance scans through all the segments in all files in the current project and, if the translation exists, prints out the source and the target of the segment:

        files = project.projectFiles;
        for (i in 0 ..< files.size())
        {
            for (j in 0 ..< files[i].entries.size())
            {
                currSegment = files[i].entries[j];
                if (project.getTranslationInfo(currSegment))
                {
                    source = currSegment.getSrcText();
                    target = project.getTranslationInfo(currSegment).translation;
                    console.println(source + " >>>> " + target);
                }
            }
        }

Prev |  | Next
Appendix E. LanguageTool plugin | Home | Appendix G. OmegaT on the web