Skip to content
Permalink
8bed31719c
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
112 lines (97 sloc) 4.11 KB
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"../../../docbook-xml-4.5/docbookx.dtd">
<appendix id="appendix.Scripts.inOmegaT">
<title>Scripts<indexterm class="singular">
<primary>Scripts</primary>
</indexterm></title>
<section>
<title>Introduction</title>
<para>OmegaT allows to run scripts written in different scripting
languages.</para>
</section>
<section>
<title>Use</title>
<para>Clicking <guisubmenu>Tools &gt;
</guisubmenu><guisubmenu>Scripting</guisubmenu> opens the Scripting
window:<screenshot>
<screeninfo>Scripting window</screeninfo>
<mediaobject>
<imageobject>
<imagedata fileref="images/ScriptingDialog.png"/>
</imageobject>
</mediaobject>
</screenshot></para>
<para>The Scripting window 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:</para>
<itemizedlist>
<listitem>
<para>Load a script into the editor by clicking on its name in the
list on the left panel.</para>
</listitem>
</itemizedlist>
<itemizedlist>
<listitem>
<para>Right-click on a button from "&lt;1&gt;" to "&lt;12&gt;" in the
bottom panel and select "Add". In the above example, two scripts
(position 1 and 2) have already been added.</para>
</listitem>
</itemizedlist>
<itemizedlist>
<listitem>
<para>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 <guisubmenu>Tools </guisubmenu>menu or by
pressing<keycap> Ctrl+Alt+F#</keycap> (# 1 to 12).</para>
</listitem>
</itemizedlist>
<para>By default, scripts are stored in the "scripts" folder located in
OmegaT installation folder (the folder that contains the OmegaT.jar).
</para>
<para>You can add new scripts there, so they will appear in the list of
available scripts in the Scripting window.</para>
</section>
<section>
<title>Scripting languages</title>
<para>The following scripting languages have been implemented:</para>
<para><itemizedlist>
<listitem>
<para><emphasis role="bold">Groovy</emphasis>
(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.</para>
</listitem>
</itemizedlist><itemizedlist>
<listitem>
<para><emphasis role="bold">JavaScript</emphasis> (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.</para>
</listitem>
</itemizedlist>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:</para>
<programlisting> files = project.projectFiles;
for (i in 0 ..&lt; files.size())
{
for (j in 0 ..&lt; files[i].entries.size())
{
currSegment = files[i].entries[j];
if (project.getTranslationInfo(currSegment))
{
source = currSegment.getSrcText();
target = project.getTranslationInfo(currSegment).translation;
console.println(source + " &gt;&gt;&gt;&gt; " + target);
}
}
}</programlisting>
</section>
</appendix>