Django

Quickstart: Transifex Native and Django

This is a quick start guide to get you through the whole Transifex Native experience.

Checkout an overview video of the Django SDK installation:

Follow the below steps to start testing Transifex Native on your Django project.

Setup Django SDK

To complete this step you will need to:

  • Install the Transifex Python toolkit in your Django project. Use the pip install transifex-python command in your console. You can also find the toolkit in PyPi: Transifex Python toolkit. Currently supported versions are Python 2.7, 3.5+, Django 1.11+.
  • Declare the installed library in your INSTALLED_APPS and set a TOKEN and SECRET that Transifex will need to provide you with. Read all the details about configuring your project.

Internationalize your code (internationalization: i18n)

Transifex Native offers its own translation hook commands both for Django templates, {% t %} , and Python views, t(). Transifex Native localization framework is using the ICU syntax to describe localization rules. Additionally you can define certain metadata parameters per string, like context, tags or character limit.

Django template simple example

Open a Django template file (e.g. an .html file) and add the following:

{% load transifex %}

<p>{% t "Hello!" %}</p>
<p>{% t "I want to be translated." %}</p>

Django view simple example

from transifex.native.django import t
from django.http import HttpResponse

def my_view(request):
    output = t("Welcome aboard!")
    return HttpResponse(output)

To see more examples on translation hooks checkout Use in Templates and Views.

Push Source Content to Transifex

This command will collect all translatable strings and push them to Transifex.

./manage.py transifex push

Checkout all available options for the push content command in Uploading source content to Transifex.

Translate Content on Transifex

After content is added in your Transifex project you and your team can use all the available tools that Transifex offers.

When a new translation is added in Transifex, it becomes available over-the-air on your Transifex Native enabled application.

The service delivering the translations to your application is called the Content Delivery Service and it's an active part of the Transifex Native solution, see more about Transifex Content Delivery Service.

📘

New translations added in Transifex will take a few minutes before being available to your application.

Display Translated Content

Transifex Native automatically displays translated content in the language currently selected in your Django project.

In order to allow changing the current language, you will need a language picker.

More specifically you will need to:

  1. Add a language picker in your Django templates.
  2. Add a route in your Project's routes.
  3. Lastly, add 'django.middleware.locale.LocaleMiddleware' in your settings.MIDDLEWARE to enable the functionality.

Checkout a detailed example in Displaying Translated Content article.