Link Transifex with GitHub
In order to find more information about the differences between Tx CLI client and a direct integration with GitHub, you can check the FAQ section here.
Simply point, click and update resources directly from Github with no coding. With the new GitHub Integration you will be able to connect a localization project in Transifex with a specific repository in GitHub using only the Transifex user interface.
To begin you require two basic steps:
Choose to link to GitHub
- Visit your Transifex Organization settings
- From the Left Hand Side Menu that appears, select Manage Integrations
- Click on the Install the Transifex App link.
- Select the GitHub Organization you wish to install the Transifex App to.
Connect the GitHub account with your localization organization in Transifex.
- Return back to the Manage Integrations Page in Transifex and click on the Authorize Transifex Link.
- Authenticate to GitHub and choose one or more repositories to make visible in Transifex. Authentication and repository selection on Github should be done by an owner (admin) of the account.
- When you are done with this process, you have authorized the selected GitHub repositories to be able to link to your organization’s localization projects.
Navigate to the project of your choice or create a new project and visit the Project settings page. In there, you will see a tab reading “Integrations”.
If the integration is set up as described in the previous step, you will see the GitHub option along with a button to Link Repository. Clicking on that button, the GitHub Integration wizard will pop up to manage the setup.
On the first step of the wizard, select the GitHub repository and branch to sync with the project.
Available repositories listed are the ones you authorized when you installed the Transifex app on the Github account you used for the integration. Also, at this point the GitHub integration works on top of a single branch.
When you are done with this step, hit Next to setup the repository files that are related to localization. In this step, you define which files you want to localize along with some extra information that are required for the integration to work. The extra information required is:
- filter_type: This specifies a directory or file
- source_file: This points to the location of the source file. In case a directory is being used, then the field "source_file_dir" must be used instead.
- file_format: This sets the type of the resources in your project, e.g. to PO. See the File formats section for details about the i18n type of each format available.
- source_file_extension: This field is required in case a directory is being used
- source_language: This is the source language of your project, such as
enfor English. This is the language you selected when you created your project.
- translation_files_expression: A path expression which reflects the file/directory structure of your translation files. The expression must contain the <lang> keyword, denoting where the file paths differentiate per language, e.g.
- language_mapping: If you use language codes other than the standard ISO ones, the integration lets you set up custom one-to-one language mappings. You'll just need to add a language_mapping section to the YAML configuration file.
The configuration follows a YAML syntax, and users can define a list of individual files or use regular expressions to match multiple files at once. Illustrated examples can be found below:
- filter_type: file
- filter_type: dir
Clicking the Next button navigates to the final step of the setup, where you will define how the syncing between Transifex and GitHub will happen.
Pulling content from the designated GitHub repository and branch happens automatically upon changes on that branch.
To push localized content from Transifex back to GitHub you have the following options:
Upon 100% translated, reviewed or proofread content.
Push content via a Pull Request on that branch, which will create a new branch with the localized content and open a Pull Request on the branch, that you can later merge directly from GitHub.
Push content via a commit back to the selected branch.
When you are done with this setup you can click Save & Sync to start syncing content from GitHub to Transifex.
In case your localization process is already in progress, and your projects/resources have already been created in Transifex, you can still use the GitHub integration syncing your existing content stored in Transifex with your files hosted in GitHub. All you need to do is to execute the steps indicated in the previous section.
Once the process is completed, you will notice that the slug of your TX resources are updated following the schema: slug = "directorystructure-filename-extension--<branch name>" where filename is the name of the file stored in GitHub, extension is the extension of the file, directorystructure is the full path of your github directory and <branch name> is the name of the GitHub branch you've selected while setting this integration up.
- Let's assume that the source file with the filename android.xml is stored in GitHub and you have already uploaded it to Transifex.
- Once the TX resource is created, Transifex automatically generates a resource slug of the format: androidxml
- Let's also assume that this file is stored in Github in the locale/i18n directory
- When you sync this resource with GitHub, the system will locate the correct TX resource and then it will change the resource slug from androidxml to locale-i18n-android-xml--master while maintaining the same name (the full path to the file is also included).
- Note: if the sync was done prior to September 28, 2019 then the slug and file name would be as seen in the image below ((the path to the file is not included)):
- Before syncing, ensure that the slug of the resources in Transifex follows the schema "filenameextension".
- Do not manually change the resource slug to "filename-extension--<branch name>".
- Synching a Single File:
filters: - filter_type: file file_format: PO source_file: locale/example.po source_language: en translation_files_expression: 'Translations/<lang>/'
- Synching Multiple Files of a Single File Type
filters: - filter_type: dir file_format: STRINGS source_file_extension: strings source_language: en source_file_dir: locale/DirTest translation_files_expression: 'Translations/<lang>'
- Synching Multiple Files of Different File Types
filters: - filter_type: dir file_format: STRINGS source_file_extension: strings source_language: en source_file_dir: locale/DirTest translation_files_expression: 'Translations/<lang>' - filter_type: dir file_format: KEYVALUEJSON source_file_extension: json source_language: en source_file_dir: locale/DirTest translation_files_expression: 'Translations/<lang>'
There is an option to send localised content to GitHub manually, without waiting for a resource to be 100% translated or reviewed. There is a "Sync Manually" option available on the Projects settings > Integrations tab in the GitHub card.
By Clicking on "Send To Github" a modal will appear requesting for the threshold localisation percentage that Transifex will check on all your project's resources.
All target languages that are localised above that threshold will be synced with GitHub using the Sync content options you have setup for the integration. For example, if you had setup GitHub integration to Sync 100% translated resources by creating a commit to the selected branch, the manual process will identify all target languages whose translation percentage is equal or above the threshold percentage you set on the modal, thereby creating a commit for each target language.
Sending less than 100% translated content to Github will include untranslated content either as empty or containing the source string as the translation. This depends on the file format.
Syncing content from GitHub to Transifex happens either upon saving or updating the integration settings on the project level or automatically whenever new content is found on GitHub (after a commit on the branch that is associated with the integration).
When a syncing process is initiated, you will be able to see that syncing is in progress in your Project settings > integrations tab under GitHub. This process could take some time, depending on the number and size of the files that are syncing.
On Project settings > integrations tab you will also be able to see details about the latest syncing with GitHub, so that you can detect any possible issues with specific files that either failed to be synced or weren’t found so that you can take some action to fix them.
Clicking on the "more" link will provide information on the last sync as seen below:
As your project evolves, you might end up in situations that you want to either extend the files you are syncing from GitHub or change the workflow of pushing localized content back on GitHub. To edit your options visit your Projects settings > integrations tab and click on the ellipsis then Edit Settings.
The interface to make the changes is the same as the one of the initial setup, but you will only be able to:
Update the detected files in the GitHub repository, by changing the YAML configuration.
Change options on how updates from Transifex are sent back to GitHub.
Please note that if you remove an already synced file or directory from the YAML configuration, the associated resource(s) will no longer be synced with the corresponding file(s) in GitHub.
Any commits or PRs that are opening due to the integration are happening from a GitHub user called Transifex-localization-platform[bot].