Django

This guide provides a step by step tutorial on how to integrate the Translation Exchange SDK with your Django 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

Use pip to download and install the SDK.

pip install django_tml  

Add 'django_tml' to your INSTALLED_APPS setting:

INSTALLED_APPS = (  
  ...
  'django_tml',
)

Add tml middleware to MIDDLEWARE_CLASSES setting:

MIDDLEWARE_CLASSES = (  
  ...
  'django_tml.middleware.TmlControllerMiddleware',
)

2. Configure the SDK

Then add the following TML configuration to setting file:

TML = {  
  'application': {
    'key': 'YOUR_APPLICATION_KEY'
  },
  'cache': {
    'enabled': True,
    'adapter': 'memcached',
    'backend': 'pylibmc'
  }
}

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

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

3. Add the Translation Exchange Script

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

{­% load tml tml_inline %­}

To activate inline translation functionality add one more line in the head section of your layout:

{­% load tml_inline_header %­}

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="default" %}

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

{% trs "Hello World" %}
# Hello World

{% tr with count=5 %} You have {count || message} {% endtr %}
# You have 5 messages

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.