HOWTO: Creating a new file filter

This HOWTO describes the creation of a new filter for use with OmegaT.

Creation of a new filter does not require programming knowledge, in Java or any other language, but you should have more than just a basic knowledge of computing generally.

The description below assumes that the file format for which you wish to write a new filter is an XML format. For the sake of example, the OmegaT version is presumed to be 1.8.0 update 01 Beta, and a new filter is to be created for the Abiword file format based upon the existing XLIFF filter.
Follow the link from the OmegaT website download page to obtain the OmegaT source code. Unpack the archive into a suitable folder.

1. Download and install Apache Ant

Apache Ant will be needed to compile the source code again after you have modified it. Other programs, such as the Java Development Kit (JDK) can also be used for this purpose, but Ant is probably the easiest to use. Download from ant.apache.org.

2. Copy an existing filter

Select an existing filter which is to serve as a basis for your new filter. In this example, the XLIFF filter is selected. This filter is in the folder at:

..\OmegaT_1.8.0_01_Beta_Source\src\org\omegat\filters3\xml\xliff

Make a copy of this folder with a suitable name, e.g. in this case:

..\OmegaT_1.8.0_01_Beta_Source\src\org\omegat\filters3\xml\abiword

In this folder, rename the files, i.e.:

XLIFFDialect.java to AbiwordDialect.java
XLIFFFilter.java to AbiwordFilter.java

Open AbiwordDialect.java and AbiwordFilter.java in turn in a text editor, and replace all instances of XLIFF, xliff, etc. with Abiword, abiword etc.

3. Identify the paragraph-level tag(s) for your file format

To find out what the paragraph tags should be, look at a sample file in a text editor. For instance, in an Abiword file (as in this example), a paragraph might look like this:

<p style="Normal">Blah blah blah blah blah. Blah blah blah blah blah. Blah blah blah blah blah. Blah blah <c props="font-weight:bold">bold</c> blah <c props="font-style:italic">italics</c>. Blah blah blah.</p>

This tells you that the paragraph tag in Abiword is <p>.

4. Define the paragraph tag(s)

In MyFilterDialect.java, in the list of paragraph-level tags, replace the existing paragraph tag(s) with the one(s) you have identified for your filter:

{
public AbiwordDialect()
{
defineParagraphTags(new String[]
{
"p", // NOI18N
});

defineOutOfTurnTags(new String[]

5. Define non-translatable tag(s)

You may need to define non-translatable tag(s) in order for your filter to work. In Abiword, for instance, the <data> tag must be defined as non-translatable:

defineIntactTags(new String[]
{
"data", // NOI18N
});
}
}

6. Add your filter to the filter master

Open the file

..\OmegaT_1.8.0_01_Beta_Source\src\org\omegat\filters2\master\FilterMaster.java

with a text editor and find the references to the XLIFF filter. Insert corresponding references for your filter, e.g.:

import org.omegat.filters3.xml.xliff.XLIFFFilter;
import org.omegat.filters3.xml.abiword.AbiwordFilter;

res.addFilter(new OneFilter(new XLIFFFilter(), false));
res.addFilter(new OneFilter(new AbiwordFilter(), false));

7. Enter your filter in Bundle.properties

Open the file:

..\OmegaT_1.8.0_01_Beta_Source\src\org\omegat\Bundle.properties

in a text editor. Find the entry for the XLIFF filter, and add a correponding entry for your new filter:

# XLIFFFilter.java

XLIFF_FILTER_NAME=XLIFF files

# AbiwordFilter.java

ABIWORD_FILTER_NAME=Abiword files

(This assumes that you are using the English version of OmegaT; make the entry in "your" language version of the Bundle.properties file if this is not the case.)

8. Compile the code

Open a command-line window (console, DOS window). Change folder to the main folder in the OmegaT source code (the folder containing the file build.xml), e.g.

cd C:\My Documents\MyOmegat\OmegaT_1.8.0_01_Beta_Source

From within this folder, execute Apache Ant by entering the Ant executable with the full path, e.g.:

C:\Program Files\apache-ant-1.7.0-bin\apache-ant-1.7.0\bin\ant

If the code compiles successfully, you will see the "BUILD SUCCESSFUL" message. If not, debugging messages will be shown which will (hopefully) provide some idea of where the problem is.

9. Launch OmegaT

If your code has compiled successfully, the compiled OmegaT is placed in:

OmegaT_1.8.0_01_Beta_Source\dist

Still in your command-line window, change to this folder, e.g. with:

cd C:\My Documents\MyOmegat\OmegaT_1.8.0_01_Beta_Source\dist

and launch OmegaT with:

java -jar OmegaT.jar

10. Check that the filter is present in OmegaT

To see your filter in the list of filters in OmegaT, select Options > File Filters > Defaults.

11. Check that your filter works

Create a new project with a sample file in the desired format.

Back to Documentation
© Marc Prior, 2008