OCA/server-tools — pull request #76 by pedrobaeza (2014-10-31 19:11:25+00:00)
Title: [ADD] transbot: Bot for synchronizing translations between Github and Transifex

I'm glad to present you Transbot, the utility I have developed for synchronize translations between OCA Github repositories and a translation editting platform.

I have selected Transifex, because it's a well know platform, that has a nice interface, with automatic suggestions between all our projects and the most important thing: it has an API that allows to interact remotely with it. I have made it through the package _txlib_, which can be downloaded from here: https://github.com/transifex/transifex-python-library, but unfortunately it can't be installed through pip or easy_install. This library is not the more efficient one, but it doesn't present any special problem and serves to do all I need. The package is not correctly detected by Odoo as an external dependency, so I have disabled this check.

On the other hand, Github presents a more complex API, and I have been struggled by some constraints with it. For example, it's very difficult to create a commit joining all the translations changed on one repo. That's why I make one commit per change. The library selected for acting as middleware with the GIthub API is the also well known PyGithub (https://github.com/jacquev6/PyGithub), which in current stable version doesn't support the possibility to make changes on repos (and the new alpha version also doesn't do it correctly), so I have injected through monkey-patching the function I need for this purpose. You can install it with `pip install PyGithub.`

The bot is presented as a regular Odoo module, so that you can reuse any possible infrastructure used in runbot for this purpose, and

Apart from the deployment requirements, these are the steps to get it properly running:

* A user and a password for Transifex. This cannot be done via a token, because Transifex doesn't allow this option. This data is stored as system parameters, so password is going to be in plain text, although in the configuration screen appears masked.
* A Transifex organization and team. Team is identified by a slug or name, derived from the real name you have put. The translation group is an id (number) that can be seen in the URL when you are on it on the web page.
* The Transifex translation group must have added the corresponding languages that can be synchronized with Github, or you will get an error on contrary. But sorry, there is no Klingon language on Transifex :wink:
* You should issue a new token for the user you want to interact with on Github, with all the permissions granted, and put on the corresponding field on the configuration.
* Last, you have to create a Github project record for each of the repos, putting the organization of the repo and the project name in it. There is no support for now for personal repos, only organization repos, but it's very easy to create an organization for you only.
* You have to click on _Get branches_ button afterwards to retrieve current branches. You can deactivate any branch you don't want in the list (for example, dev branches).
* Then, you can click on _Check Github updates_ to query active branches of the current project for new files, creating a Transifex project for each branch with this convention: ` ()`, and uploading pot and po files. Here there can be errors that are logged (for example, an empty translation file like fr_BE.po in vertical-hotel).
* After this, you can click also on `Check Transifex updates`, which detects possible changes on translation strings on Transifex, and dump back on Github. This is awfully slow, but there's no other way, because it has to download each translation strings and check against saved hash, because Transifex doesn't provide any other method.

Any suggestion or question, just tell me.

Enjoy!