English
open-tran

Developers

This page is dedicated to all developers that would like to help us develop the service, create new tools or integrate it in the existing software.

Contents

  1. API Introduction
    1. Suggestions
    2. Projects
    3. Example
  2. JSON API
  3. XML-RPC API
    1. Python
    2. C
    3. Java
  4. Off-line mode
    1. Installing
    2. Database
    3. Algorithm

API Introduction

Open-Tran.eu has been providing an API since its inception in February, 2007. This section tries to describe the fundamental concepts and illustrate them with an example.

Suggestions

Whenever translation suggestions are requested, the server prepares the result as a set of objects. These objects are then either rendered in HTML (if the request came from user's browser) or serialized into JSON or XML. However they wouldn't be sent, every suggestion in the list have the same set of fields described below.

Projects

Every project within Open-Tran is identified with a single-letter code. Furthermore, Open-Tran hosts the icons used to identify the projects. Below is a table of the projects and their codes and icons.

CodeNameIcon
AMandriva /images/mandriva-logo.png
DDebian Installer /images/debian-logo.png
FCor Jousma /images/pompelyts.png
GGNOME /images/gnome-logo.png
IInkscape /images/inkscape-logo.png
KKDE /images/kde-logo.png
MMozilla /images/mozilla-logo.png
OOpenOffice.org /images/oo-logo.png
RFedora /images/fedora-logo.png
SopenSUSE /images/suse-logo.png
XXFCE /images/xfce-logo.png

Notice that some of the logos might be copyrighted and their use might be restricted. Open-Tran hosts them in order to make sure that they are always available from the same location and in order to avoid so-called hot-linking.

Example

As an example, consider the excerpt of the results from http://en.es.open-tran.eu/suggest/file:
API example
Notice, that different spellings of the word archivo are separated from each other. Every distinctive spelling is a separate suggestion. So let us first dive into the marked suggestions:

  1. archivo %S
  2. Tipo de archivo

JSON API

You can fetch the suggestions in the JSON format by requesting the results from a URL in the format exemplified here:

  http://en.es.open-tran.eu/json/suggest/file

The above URL requests that the server provides suggestions of translations of the word file from English into Spanish. In response, the server sends a list with the suggestions. Every suggestion is an object described in the documentation of the XML-RPC calls. You may also refer to a commented excerpt of an output for the request http://en.id.open-tran.eu/json/suggest/save as.

Additionally, you can fetch a list of all supported language codes by requesting the URL:

  http://open-tran.eu/json/supported

XML-RPC API

The interface is exported through the XML-RPC protocol. You can fetch the suggestions from the server using your own software by sending a request to the server and fetching an XML response with the results. The following link will take you to the documentation of all exported functions. An example response from the server (for the execution of suggest("save as", "pl") is here: save_as.xml.

Below is the list of programming languages with code snippets (or links to such) that give an example of how to access the Open-Tran service with it.

Python

Below is an example of a very simple python script that searches for translations of the phrase "save as" from English to Brazilian Portugese.

      from xmlrpclib import ServerProxy

      lang = "pt_br" # replace with your language code
      server = ServerProxy("http://open-tran.eu/RPC2")
      for sugg in server.suggest("save as", lang):
          print sugg
    

C

Ignacio Casal Quinteiro contributed an example implementation in C.

Java

Yves Savourel contributed an example implementation in Java.

  import org.apache.xmlrpc.XmlRpcException;
  import org.apache.xmlrpc.client.XmlRpcClient;
  import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;

  public void queryOpenTran (String textToQuery,
	String sourceLanguage,
	String targetLanguage)
  {
  	try {
		// Setup the XML-RPC client
		XmlRpcClient client;
		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
		config.setServerURL(new URL("http://open-tran.eu/RPC2"));
		client = new XmlRpcClient();
		client.setConfig(config);
			
		// Prepare the query parameters
		Object[] params = new Object[] {
			new String(textToQuery),
			new String(sourceLanguage),
			new String(targetLanguage)};
		// Execute the query
		Object[] results = (Object[])client.execute("suggest2", params);
		
		// Parse the result back
		StringBuilder tmp = new StringBuilder();
		for ( Object obj1 : results ) {
			tmp.setLength(0);
			Map map1 = (Map)obj1;
			tmp.append(String.format("Translation=\"%s\"", (String)map1.get("text")));
			tmp.append(String.format(", value=%d", (Integer)map1.get("value")));
			tmp.append(String.format(", count=%d", (Integer)map1.get("count")));
			Object[] projects = (Object[])map1.get("projects");
			for ( Object obj2 : projects ) {
				Map map2 = (Map)obj2;
				tmp.append(String.format("\nProject: name=", (String)map2.get("name"))); 
				tmp.append(String.format("\n  original=\"%s\"", (String)map2.get("orig_phrase")));
				tmp.append(String.format("\n  flags=%d", (Integer)map2.get("flags")));
				tmp.append(String.format("\n  path=%s", (String)map2.get("path")));
				tmp.append(String.format("\n  count=%d", (Integer)map2.get("count")));
			}
			System.out.println(tmp.toString());
		}
		
	}
	catch ( Throwable e ) {
		e.printStackTrace();
	}
  }

Off-line mode

Since June, 2008 it is possible to use the Open-Tran service in an off-line mode. Once the user downloads the databases, she may query it localy. The off-line access has one important advantage: it returns the results almost instantly.

Installing

First, go to our FTP site at ftp://open-tran.eu and download two databases: an English one (currently: ftp://open-tran.eu/ten-en.db) and one for your language (for example: ftp://open-tran.eu/ten-pt_br.db for Brazilian Portuguese). The databases have to be stored (or symlinked) in the .open-tran directory in the user's home directory.

You will also need to download the software from ftp://open-tran.eu/open-tran-latest.tar.gz. Currently, there are two tools in the tarball:

  1. suggest.py is a console script that may be run like this: suggest.py "save as" es
  2. open-tran.py is a GTK-based GUI tool that has never really been completed. I thought that I would be able to create a po-editor within few hours but it turned out to be a wrong assumption :)

Database

Open-Tran stores the phrases in SQLite3 databases. Below is the diagram depicting the current database schema. You can find the SQL for it in the repository.
database diagram
The field length in the table Phrases holds the number of words in the phrase and there is currently only one flag: value 1 indicates that the translation is fuzzy.

Algorithm

Open-Tran first tries to find the most similar phrase in the original language. In order to do that, we compute the number of words that are not in the intersection of the phrases. The lower the number, the better. As an example consider the following situation: we are looking for the phrase "do you really want to save". Let's consider the following candidates:

candidatescore
do you really want to quit2 (quit, save)
save what you want3 (what, do, really)

Once we find the best matches, we locate their translations via their locationid.