Fetching Translations from Transifex
With Transifex Native translations are fetched continuously over the air (OTA) to your application. There is no need to restart your server or deploy code to see newest translations.
What actually happens is:
- The first time the application starts, the integration populates its internal memory with the state of translations in Transifex.
- A daemon (thread) runs in the background to periodically re-fetch translations and update the internal memory accordingly.
The translations are available while your application is running, on a developer's local environment working on a new code or on your production where your users interact with the application.
However, it does not start by default when running a Django shell or any of the
./manage.py <command> commands. which means that in those cases, by default, translations will not be available on your application.
Force translation sync
Translations are available over the air (OTA) for your application when the Django server is running and listening for HTTP requests.
However if you need to run Django shell or Django commands and have Transifex Native provide localized content, you can achieve it by using the
FORCE_TRANSLATIONS_SYNC environment variable. Having this variable enabled, will start the daemon and fetch translations periodically.
For example, if you want to run a Django shell with translations available and receive OTA translation updates, you can do so by running:
FORCE_TRANSLATIONS_SYNC=true ./manage.py shell
Manage fetched languages
By default, Transifex Python SDK will fetch (over the air) the languages defined in the
For example, let's say that on Transifex, the Native project has the following languages added:
en, fr, de.
And Django has the following setting in place:
LANGUAGES = [("en", "English"), ("fr", "French), ("es", "Spanish")]
The SDK will fetch the intersection of both the remote languages and the Django languages:
There are cases (e.g. when developing a Microservice or an API service with Python), that you need to fetch ALL the available languages from Transifex.
To override the behaviour above, you can set the following setting in Django:
TRANSIFEX_FETCH_ALL_LANGUAGES = True
This will tell the SDK to populate the cache with all the remote translations, regardless of the LANGUAGES setting.
This way, you can create custom logic, by manually setting the current language. For example:
from django.shortcuts import render from django.utils.translation import activate def django_view(request): activate(request.GET.get('lang')) return render(request, "main.html")
This functionality is supported on transifex-python >= 2.1.0
Updated over 1 year ago