GitHub is central to many development teams' workflows. In this guide, you'll learn how to synchronize changes between files hosted on GitHub and your localization projects in Transifex. We will show you how to do this with the Transifex GO CLI and use it in conjunction with a Continuous Integration tool for a more automated workflow.
Syncing a local project to Transifex with the Transifex Go Client
Let's say you made changes in your code, and new strings need to be translated. You can use the Transifex Go CLI to push these source changes to Transifex.
Here are the steps to sync a local project to Transifex using the Go CLI:
git pullto ensure your local repository is up to date with the remote GitHub repository.
Install the Transifex Go Client if it's not already installed. You can find detailed instructions on how to do this here. The Transifex Go Client is based on the Git client and uses a similar command structure.
Create a project in Transifex if you don't have one yet. This project will be used for localizing the resources in your GitHub repository.
From your GitHub repository root, run the
tx initcommand to initialize your local project configuration.
$ tx init
Successful creation of '.tx/config' file
You should now have a .tx folder inside your repository. Inside this folder, a configuration file will contain the information used to identify the project on a Transifex server.
The next thing we need to do is add resources to the configuration file. The simplest way to do this is with the tx add command, which will start an interactive session:
Now, your .tx/config should look like this:
host = https://app.transifex.com
source_file = locale/en.php
file_filter = locale/<lang>.php
type = PHP
resource_name = Web Application
Repeat the same steps for all the files you want to include in your localization process, then add the .tx folder to your Git repository using the
git addcommand. When other developers pull your changes, they can use the same configuration file to connect their Transifex clients to the Transifex project.
When you're ready to push your updated files to Transifex, use the tx push command. The
-s flag pushes source files while the
-t flag pushes translation files, and
-a will push all available locales:
$ tx push -s -t -a
To pull changes into your local project folder, use
$ tx pull -a
From here, simply stage, commit, and then push the updated localization files to your GitHub repository.
Integrating the Transifex GO CLI with Travis CI
You can automate the above process and create a continuous localization workflow by incorporating the Transifex GO CLI into your continuous integration chain. Here's how to do it:
Follow the steps above to set up your .tx/config file and commit it to your git branch.
Visit the Travis CI website and create an account if you don't have one yet.
Head to travis-ci.org/profile and enable travis-ci for your repository.
On your enabled repository, hit More Options> Settings at the top right.
In the Environment Variables section, add two new secret env vars. You can use
Inside your repository, add a .travis.yml file if you don't already have one. We will install Transifex Client and push if the tests pass successfully. Once you have a .travis.yml file, add a section like this inside of it:
- pip install virtualenv
- virtualenv ~/env
- source ~/env/bin/activate
- pip install transifex-client
- sudo echo $'[https://app.transifex.com]\nhostname = https://app.transifex.com\nusername = '"$TRANSIFEX_USER"$'\npassword = '"$TRANSIFEX_PASSWORD"$'\ntoken = '"$TRANSIFEX_API_TOKEN"$'\n' > ~/.transifexrc
- tx push -s
Commit the travis.yml file to the branch you want to sync translations from. Now, every time you commit changes in this branch, your content will be uploaded to Transifex, and your resources will be updated automatically.
Looking for more help? Get support from our Transifex Community Forum!
Find answers or post to get help from Transifex Support and our Community.