Getting Started with J2EE

This guide provides a step by step tutorial on how to integrate the Translation Exchange SDK with your Java based web applications and allow you to translate your site into multiple languages.

Before Getting Started

Make sure you have a Translation Exchange account, and have created a project in your dashboard.

1. Install the SDK

To download and install the SDK you currently have the following options.

Plain-old JAR

Download the following JARs and put them on your test classpath:


Add dependencies to com.translationexchange:tml, com.translationexchange:tml-memcached in the preferred scope. (Note: 0.2.2 is the latest stable version for tml.)


2. Configure the SDK

For the best performance, translations should be cached in your application. Multiple cache adapters are supported.

Configure the SDK in your application by extending the method configureTml() in TmlListener class:

import com.translationexchange.core.Tml;  
import com.translationexchange.core.Utils;  
import com.translationexchange.j2ee.listeners.TmlListener;

public class AppListener extends TmlListener {  
  protected void configureTml() {
            "key", "e9ecde2f25c1fed5c555e4bb036210fcde472536f5d71cc8b85f3508de9c845c",    
            "host", "",
           // "cdn_host", ""

        "host", ""

         "enabled",  true,  
         "class",    "com.translationexchange.cache.Memcached",
         "host",     "localhost:11211",
         "namespace", "e9ecde2f25c1",
         //"version_check_interval", 10

To learn more about configuring the SDK, go to the Java Configuration section of the docs.

3. Add the Translation Exchange Script

On top of your jsp file load tag library with prefix tml:

<%@ page contentType="text/html; charset=UTF-8" %>  
<%@ taglib prefix="tml" uri="" %>  

Copy and paste the following code between the <head> and </head> tags of your layout file(s).


Use the following code anywhere on your page to add a language selector. Optionally, you can pass the type of selector you want.

<tml:language_selector type="sideflags" />  

There are a few language selectors to choose from. You can view all the available selectors or learn how to create your own in the Language Selectors section of the docs.

4. Mark Up Your Content

<tml:tr label="Hello World"/>  
# Hello World

<tml:tr label="You have {count || message}" count="5" />  
# You have 5 messages

<tml:tr label="{user} sent {target} [bold: {count || gift}]" token.user="${current_user}""${users.anna}" token.count="1" />  
# Michael sent Anna 1 gift

<tml:tr label="{user} uploaded [bold: {count || photo}] to {actor | his, her} album." user="${current_user}" actor="${users.sam}" count="4" />  
# Michael uploaded 4 photos to his album.

Learn more about marking up your content in the Translation Markup section of the docs

5. Activate Translation Mode

Once the script has been added to your layout you can start using translation mode. To activate translation mode, press CTRL+Shift+i on your keyboard.

Once translation mode has been activated, the content of your application will be synchronized with Translation Exchange and your strings will appear in your Dashboard.

Make sure to browse your entire application while in translation mode to ensure that all your content gets sent to the Translation Exchange service.

Now that your strings have been synchronized, you can start translating. Go to the Translation Options section of the docs to learn more about the different ways your content can be translated.

Make sure to Publish your translations so that they can be seen by your users.

6. Sample Applications

The best way to start using the SDK is to run a sample application that comes bundled with this SDK.

Before Running the Sample Application

Make sure you have Maven, Apache, Eclipse for J2EE installed.

git clone  
cd ./tml-java-j2ee-samples-welp  

Import the project into Eclipse by specifying the directory. Using the Maven plugin run the project as web application.