# File Filters

- File filters dialog
  - Filters options
  - Edit filter dialog
    - Source file type, filename pattern.
    - Source and target files encoding
    - Target filename
      - Add/edit pattern dialog

OmegaT features highly customizable filters, enabling you to setup most of the aspects of their work. File filters are pieces of code capable of:

- Reading the document in some specific file format. For instance, plaintext files.
- Extracting the translatable content out of the file.
- Automating modifications of the translated document file names by replacing translatable Contents with its translation.

Most of the users should be happy with default file filter options. If you are not, open the main dialog by selecting Options → File Filters... from the main menu.

Warning! Changing the filters options when a project is open may cause data loss. If you change filters options when a project is open, you will have to reload the project for the changes to take effect.

# File filters dialog

The dialog lists available file filters. If you don't want to use OmegaT to translate the files of some type, you may turn off the filter by unticking the check box near its name. OmegaT will then omit the appropriate files while loading projects, and will copy them untouched while creating target documents. Later when you decide to use the filter again, just tick the check box.

Click Defaults to reset the file filters to the default settings.

To edit what files in what encodings the filter will process, select the filter from the list and click Edit.

## Filters options

Three filters have specific options. To modify the options select the filter from the list and click Options. The filters with their respective available options are:

- Text Files
  Paragraph segmentation on line breaks, empty lines or never
    If sentence segmentation rules are active, the text will further be segmented following the available rules.
- XHTML Files
  Attributes translation
    The selected attributes will appear as segments in the Editor window.
  Paragraph on <br>
    The <br> HTML tag will create a paragraph for segmentation purposes.
- HTML and XHTML Files
  Encoding declaration
    OmegaT may add or rewrite the file's encoding declaration based on the target file selected encoding.
  Attributes translation
    The selected attributes will appear as segments in the Editor window.
  Paragraph on <br>
    The <br> HTML tag will create a paragraph for segmentation purposes.

## Edit filter dialog

The dialog allows you to setup the source filename patterns of files the filter will process, customize the filenames of translated files, and select what encodings it will use for loading the file and saving its translated counterpart.

To modify a file filter pattern, either modify the fields directly or click Edit.

To add a new file filter pattern, click Add.

The same dialog is used to add a pattern or to edit a particular pattern. The dialog is useful because it includes a special target filename pattern editor allows you to customize the names of output files.

### Source file type, filename pattern

When an OmegaT encounters a file in its source directory, it tries to select the filter using file's extension. More precisely, OmegaT tries to match each filter's source filename patterns against the filename.

For example, `*.xhtml` pattern will match against any file with `.xhtml` extension. If the appropriate filter is found, it is given the file for processing. For example, by default XHTML filter will be used for processing files with `.xhtml` extension.

You may change or add filename patterns of files each file filter will handle.

Source filename pattern use wild card characters similar to those used in Searches.

The '*' character matches zero or more characters. The '?' character matches exactly one character. All the other characters represent themselves.

For example, if you want the text filter to handle readme files (`readme`, `read.me`, and `readme.txt`) you should use the pattern `read*`.

### Source and target files encoding

Only a limited number of file formats specify a mandatory encoding.

File formats that do not specify their encoding will use the encoding you set up for the extension that matches their name. For example, by default `.txt` files will be loaded using OS-default encoding. You may change the source encoding for each different source filename pattern.

Such files may also be written out in any encoding. By default, the translated file encoding in is the same as the source file encoding.

Source and target encoding fields use combo boxes with all supported encodings included. <auto> leaves the encoding choice to OmegaT. Here's how it does:

- OmegaT finds the source file encoding by using its encoding declaration if any (HTML files, XML based files).
- OmegaT is set to use a mandatory encoding for some file formats ( Java properties etc)
- OmegaT uses the default encoding of the operating system for text files.

### Target filename

Sometimes you may like to rename the files you translate automatically, for example adding a language code after file name.

Target filename pattern uses a special syntax, so if you wish to edit this field, you should better click Edit... to go to the Edit Pattern Dialog. If you want to fall back to default configuration of the filter, click Defaults.

You may also modify the name directly in the target filename pattern field of the file filters dialog.

#### Add/edit pattern dialog

- Default is `${filename}` -- full filename of the source file with extension, so that the name of the translated file is the same as the name of the source file.
- `${nameOnly}` allows you to insert only the name of the source file without the extension.
- `${extension}` -- the extension of the source file.
- `${targetLocale}` - target locale code (of a form "xx_YY").
- `${targetLanguage}` - the target language and country code together (of a form "XX-YY").
- `${targetLanguageCode}` - the target language only ("XX").
- `${targetCoutryCode}` - the target country only ("YY").

Legal notices