HOWTO: Creating a new file filterThis 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.
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.
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.
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>.
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[]
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
});
}
}
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));
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.)
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.
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
Back
to Documentation
©
Marc Prior, 2008