|
Components |
Okapi FrameworkComponents |
![]() |
The Okapi Framework comes with a collection of various components and libraries that are used in the okapi applications, but can also be utilized by any developer as a toolkit to quickly put together powerful and specialized processes related to translation and localization.
An important type of component in the framework is the filter. Filters allow you to read a given document and get access to its content using the same API regardless of the file format.
The following list shows some of the filters available with the framework:
Another important type of component in the framework is the step. Steps are self-contained parts that takes an input, perform one specific task, and send an output. The steps are chained together into a pipeline.
The following list shows some of the steps available with the framework:
Rainbow has several modules that are not implemented (yet) as steps. The following list shows some of those utilities:
Here is a simple example of how you can use the framework's components in your own code:
The Java code below opens a properties file or an OpenOffice.org document and display all the translatable text inside.
import java.io.File;
import net.sf.okapi.common.LocaleId;
import net.sf.okapi.common.Event;
import net.sf.okapi.common.EventType;
import net.sf.okapi.common.filters.IFilter;
import net.sf.okapi.common.filterwriter.GenericContent;
import net.sf.okapi.filters.openoffice.OpenOfficeFilter;
import net.sf.okapi.filters.properties.PropertiesFilter;
public class Main {
public static void main (String[] args) {
try {
IFilter filter = null;
if ( args[0].endsWith(".properties") ) {
filter = new PropertiesFilter();
}
else if ( args[0].endsWith(".odt") ) {
filter = new OpenOfficeFilter();
}
// Open the document to process
filter.open(new RawDocument(new File(args[0]).toURI(),
"UTF-8", LocaleId.fromString("en")));
// Create a formatter to display text unit more prettily.
GenericContent fmt = new GenericContent();
// Process the input document
while ( filter.hasNext() ) {
Event event = filter.next();
if ( event.getEventType() == EventType.TEXT_UNIT ) {
// Format and print out each text unit
fmt.setContent(((TextUnit)event.getResource()
).getSourceContent());
System.out.println(fmt.toString());
}
}
}
catch ( Throwable e ) {
e.printStackTrace();
}
}
}