Click or drag to resize
The File Writer

The last step in the localization workflow is the generation of the (translated) target file in the original document format. In one of the examples provided in this SDK we need to write all translated segments from a bilingual SDL XLIFF document to a (native)SubRip file. This task is performed by a Native API Writer.

When implementing a Native API file writer you must derive your writer class from the interfaces INativeFileTypeComponent and INativeFileWriter. These interfaces provide a way of connecting to the SDL File Type Support Framework and allowing it to initialize the writer with the objects it needs to interact with the SDL File Type Support Framework. A writer will also normally derive from the INativeOutputSettingsAware, INativeContentCycleAware and ISettingsAware interfaces, which provide the writer with additional information such as the target file path name, the target language and the preferred encoding of the target file and also allow any required settings to be populated.

However, the simplest way to implement a native writer is to merely derive it from the AbstractNativeFileWriter class and the INativeContentCycleAware interfaces, and use the helper functions of the AbstractNativeFileWriter class.

The AbstractNativeFileWriter base class provides an implementation of the INativeFilterComponent, IAbstractNativeContentHandler and INativeOutputSettingsAware interfaces leaving only the INativeContentCycleAware interface to be implemented by the derived class. If this AbstractNativeFileWriter class is used as a base class, in its implementations of IAbstractNativeContentHandler it provides some default (empty) implementations of the interface methods. These public virtual methods can be overwritten in the derived class if an implementation is required for a particular native writer.

You may have noticed that the IAbstractNativeContentHandler interface, from which the Native API writer is derived, is the same interface that is used for the Output property of the AbstractNativeFileParser base parser class. The reason for this is that all text, tags and other mark-up items that are written during the parsing phase are re-used when the translated output file is being creating, with the mark-up order and translated text content determined by the translation process. However, the translated document will only contain tags that were created during the parsing phase. The Native API writer can rely on the tag content of each tag to be the same as it was when it was written by the parser with the exception of any manually-added mark-up items in a framework-based editor. If a filter allows for manually created mark-up such as Bold, Italic or Underline formatting added by the user during translation, then this will be defined in the File Type Component Builder. The only other exception to this is when the parser class has created a tag with localizable content in it. If this is the case, then the LocalizableContent property of the tag properties must be examined to retrieve the text for the localizable sub-segments.

The AbstractNativeFileWriter base class provides some default virtual implementations of the IAbstractNativeContentHandler interface methods that represent tags, text and futher mark-up item in the translated document. Therefore, in your derived Native API writer class, you only need to implement the overridable methods for the text or mark-up that is applicable to your document type. A list of overridable methods is provided below. If however, you are not deriving from AbstractNativeFileWriter, you will need to implement all of the following methods, even if the method content is empty.

The AbstractNativeFileWriter interface contains two further methods that need to be implemented in any writer class. These are outlined below:

The ISettingsAware interface contains one method that needs to be implemented in any writer class, which requires access to any settings the writer may need. This is shown below:

Community
Edit
Be the first to Edit the community content of this topic.
Comments