| Opening the File for Parsing |
In this step you will learn how to implement the class that extracts translatable text from a given bilingual source (BIL) file.
Start by adding a class called e.g. BilParser1.cs to your project. Your parser class needs to reference the following namespaces:
Then, your parser needs to be derived from the following class and interfaces:
First, add the following global class members:
private IPersistentFileConversionProperties _fileProperties; private XmlDocument _document; public event EventHandler<ProgressEventArgs> Progress;
We require the _fileProperties object from which we can retrieve important information on a given input file, primarily the file path and name. We also require an XML document object (_document), which we can parse using the XML DOM API. It is recommended (but not required) that you implement a progress reporter event. Depending on the size of your input file, parsing may take time. Therefore it is useful to inform the end user of the file parsing progress by implementing a progress report mechanism.
Now you need to add the following members of the INativeContentCycleAware interface:
public void SetFileProperties(IFileProperties properties) { _fileProperties = properties.FileConversionProperties; Output.Initialize(DocumentProperties); IFileProperties fileInfo = ItemFactory.CreateFileProperties(); fileInfo.FileConversionProperties = _fileProperties; Output.SetFileProperties(fileInfo); }
Then, add the following member, which the input file into the XML DOM object. At the same time, you can use this member to set the progress reporter to 0%:
public void StartOfInput() { OnProgress(0); _document = new XmlDocument(); _document.Load(_fileProperties.OriginalFilePath); }
The interface also requires you to add the following member, in which you implement the logic that should be applied when reaching the end of the input file. For example, you can set the XML DOM object to null and the progress reporter to 100%, as the file has been fully parsed. Since the plugin also uses an Output object, which is for example used by Studio to write sdlxliff files, you also need to call the FileComplete and Complete functions of the writer, to properly finalize the created file.
public void EndOfInput() { // done with the file Output.FileComplete(); // done with the document Output.Complete(); OnProgress(100); _document = null; }
Next, add the following (optional) OnProgress() method, which takes a byte parameter to set the progress within the range of 0 and 100%:
protected virtual void OnProgress(byte percent) { if (Progress != null) { Progress(this, new ProgressEventArgs(percent)); } }
Add the following required members of the bilingual parser interface:
public IDocumentProperties DocumentProperties { get; set; } public IBilingualContentHandler Output { get; set; }
The output member handles the output to the bilingual document. Through this member you will later determine the paragraphs, segment pairs, etc. that are written to the bilingual file.
Add the following member, which takes care of the actual file parsing operation. Note that no actual file content is parsed for the moment. We will implement the logic for parsing the file content later by adding helper functions to our parser component.
public bool ParseNext() { return false; }
At this point you could already build your project, however, your file type plug-in will only generate an empty bilingual document, which would look in SDL Trados Studio 2017 as shown below:

The resulting intermediary (SDL XLIFF) file would merely contain the basic header information that was retrieved from the document and file properties objects such as the original file name, the source/target language, the SDL File Type Support Framework version, etc.
Do not forget to add the parser component to the File Type Component Builder by inserting the following code to your implementation of the IFileTypeComponentBuilder interface. Remember that failure to do so will mean that this component will never be used by the file type plug-in, even if the parser has been implemented in the assembly.
public IFileExtractor BuildFileExtractor(string name) { var parser = new BilParser(); var extractor = this.FileTypeManager.BuildFileExtractor(parser, this); return extractor; }