Django CMS has built-in support for internationalization (i18n). This makes it easy to localize your website using PO files and the Transifex Client.
Localizing with Django's built-in i18n support
Django CMS relies on the Django framework's internationalization support. If you are unfamiliar with this, check out the Django documentation. More specific information regarding Django CMS can be found in the Django CMS documentation.
The source file will be the foundation for setting up the Transifex Client, which lets you send and receive files over Transifex's REST API. To set up your Transifex Client configuration, you first need a project in Transifex, and the Transifex Client installed.
After finishing all the steps above, follow the set of commands below to set up your repository configuration in a file called .tx/config. In this example, we named our project in Transifex mytxproject
.
```
$ git clone http://git.example.com/git/myapp.git
$ cd myapp
$ tx init
$ tx set --auto-local -r mytxproject.defaultpo 'locale/<lang>/LC_MESSAGES/default.po' \
--source-lang en --type PO --source-file locale/en/LC_MESSAGES/default.po
```
The resulting .tx/config content should look like this:
```
[main]
host = https://app.transifex.com
[myproject.myapp]
file_filter = myapp/locale/<lang>/LC_MESSAGES/django.po
source_file = myapp/locale/en/LC_MESSAGES/django.po
source_lang = en
type = PO
```
We recommend that you commit the .tx/config
file to your repository for the next time you want to push new source content.
Next, cd into the app_dir (cd myapp in our example) and create a locale folder (mkdir locale). If that folder is already available, skip that step. Then run: $ django-admin makemessages -l en $ tx push -s
The tx
commands should always be executed from the directory in your repository where the .tx/
folder is located.
๐กTip: Add "-d djangojs" to generate translations for JavaScript assets.
To download translations once they are complete in Transifex, use the following:
```
$ cd myapp
$ tx pull -t -a
```
๐กTip: Make sure to always PULL translations first before PUSHING. Translations should happen on Transifex and not locally in the .po files for the addons registered on Transifex. If your project already has translations, make sure to push them first to Transifex using tx push -f -t --no-interactive
.
To download translations once they are complete in Transifex, use the following:
```
$ cd myapp
$ tx pull -t -a
```
Updating source strings in Transifex from Django CMS
Update your local repository by pulling the latest data from Transifex. From the root:
```
$ tx pull -s -a
```
Add -f to force. Create the latest messages from the source language (English). From the root:
```
$ cd app_dir
$ django-admin makemessages -l en
```
Push the translations back to Transifex. From the root:
```
$ tx push -s -l en
```
This will push the English source translation to Transifex.
Updating Django CMS with the latest translations from Transifex
Update your local repository by pulling the latest data from Transifex. From the root:
```
$ tx pull -s -a
```
Create the machine-readable translations by compiling them. From the root:
```
$ cd app_dir
$ django-admin compilemessages
```
Commit these translations to your GitHub repository.
๐กTip
Looking for more help? Get support from our Transifex Community Forum!
Find answers or post to get help from Transifex Support and our Community.