Howto - Creating a new file filter

This HowTo explains how to create a new file filter for use with OmegaT by describing the creation of a rudimentary file filter for the TMX format. Although it might seem strange to want to translate TMX files (the usual reason for creating a file filter), the addition of a TMX filter has the interesting effect that it enables TMX files in any location to be searched for from within any OmegaT project using the "Search Files" function, something not possible in the standard OmegaT build.

For compiling OmegaT from the source code, see Compiling OmegaT from Source HowTo.

Select an existing filter for a format similar to that for the new filter. In this example, the Help & Manual filter has been selected as a basis.

Locate the folder src/org/omegat/filters3/xml, and make a copy the subfolder /helpandmanual, naming it /tmx. In this folder, rename the two files HelpandManualDialect.java and HelpandManualFilter.java to TmxDialect.java and TmxFilter.java respectively.

Open the files TMXDialect.java and TMX filter in a text editor. In both files, search for (matching the case) and replace:

"helpandmanual" with "tmx"
"HelpAndManual" with "TMX"
"HELPANDMANUAL" with "TMX"
"Help & Manual" with "TMX"
"Help&Manual" with "TMX"

Identify the paragraph-level tag(s) for your new file format. To find out what the paragraph tags should be, examine a sample file in a text editor. In TMX, the paragraph-level tag corresponding to a segment is "tu".

In TMXDialect.java:

Define the paragraph tags, in this case by changing the line:

   defineParagraphTags(new String[] { "caption", "config-value", "variable", "para", "title", "keyword", "li", });

to

   defineParagraphTags(new String[] { "tu", });

You can delete the line:

   defineShortcut("link", "li");

as it is irrelevant to TMX, although the new filter will still work if you do not.

You can define out-of-turn tags. These define subsegments that are presented outside the segment in which they are contained (footnotes are a good example). To do this for the TMX filter, insert the line

   defineOutOfTurnTags(new String[] { "sub", });

beneath the line

   defineParagraphTags(new String[] { "tu", });

The filter will however still work if you do not do this.

Beneath these lines, you can also insert the code:

   defineIntactTags(new String[]
   {
   "header",
   "prop",
   "ph",
   "bpt",
   "ept",
   "it",
   "ut",
   });

This will make the display of the TMX files neater, but again, it is not absolutely essential.

In TMXFilter.java:

Change the file extension, in this case to .tmx, by changing the line:

   public Instance[] getDefaultInstances() {
   return new Instance[] { new Instance("*.xml", null, null), new Instance("*.hmxp", null, null), };

to:

   public Instance[] getDefaultInstances() {
   return new Instance[] { new Instance("*.tmx", null, null), };

In the folder /src/org/omegat, open the file Bundle.properties in a text editor and find the lines

   # HelpAndManualFilter.java
   HELPANDMANUAL_FILTER_NAME=Help & Manual Files

Below these lines, insert the lines

   # TMXFilter.java
   TMX_FILTER_NAME=TMX files

(If you wish to launch OmegaT with a user interface language other than English, make the same change in the relevant localized Bundle.properties file.)

In the main folder of the source code, open the file manifest-template.mf in a text editor. Find the lines:

   Name: org.omegat.filters3.xml.helpandmanual.HelpAndManualFilter
   OmegaT-Plugin: filter

Below them, insert the lines:

   Name: org.omegat.filters3.xml.tmx.TMXFilter
   OmegaT-Plugin: filter

Compile as described in the Compiling OmegaT from Source HowTo. Launch the newly compiled version. Check in Options > File Filters that the new filter is present. To check whether it works, you can place a TMX file in the /source folder of a project, or (more useful) perform a Text Search > Search files operation on TMX files.

Copyright Marc Prior 2008-2011