Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 76 lines (61 sloc) 3.25 KB
#!/usr/bin/env python
# fetch latest translations from Transifex and commit them
import argparse
import os
import subprocess
from datetime import datetime
# '--minimum-perc', '10',
# path_to_tx = len(sys.argv) > 1 and sys.argv[1] or utils.find_dot_tx()
def pull_project_translation(path_to_tx):
"""Fetch the translations from Transifex
path_to_tx: path containing a .tx/config file
print("Fetching translations at %s" %
print("Pulling to %s" % path_to_tx)
# tx uses timestamp to know if we should fetch translations, git doesn't give a shit about timestamp'touch -d "$(date -R --date=\'21 days ago\')" */i18n/*', shell=True)'touch -d "$(date -R --date=\'21 days ago\')" addons/*/i18n/*', shell=True)'touch -d "$(date -R --date=\'21 days ago\')" openerp/addons/*/i18n/*', shell=True)'touch -d "$(date -R --date=\'21 days ago\')" odoo/addons/*/i18n/*', shell=True)'touch -d "$(date -R --date=\'21 days ago\')" locale/*/LC_MESSAGES/*', shell=True)
# commands.cmd_pull(PULL_ARGS, path_to_tx)['tx', 'pull'] + PULL_ARGS)
# remove changes with only Last-Translator or PO-Revision-Date"""git status --short | grep '.po' | grep -v "^??" | sed 's/^ M *//' | sed 's/^?? *//' | xargs -I {} bash -c 'if test `git diff {} | grep "^+" | grep -v "^+++\|^+#\|Last-Translator\|PO-Revision-Date" | wc -l` -eq 0; then git checkout -- {}; fi'""", shell=True)
print("Done fetching at %s" %
def commit_translations(code_path, commit=False, push=False):
"""Reset the code in :code_path: on current remote and push the new translations"""
msg = "[I18N] Update translation terms from Transifex"
branch = subprocess.check_output('git symbolic-ref -q --short HEAD', shell=True).replace('\n', '') # branch name
remote = subprocess.check_output(['git', 'config', 'branch.%s.remote' % branch]).replace('\n', '') # remote name
print("Working with to %s/%s" % (remote, branch))
if commit:
# make have same code as remote['git', 'fetch', remote, branch])['git', 'reset', '%s/%s' % (remote, branch), '--hard'])
if commit:
# add new files['git', 'add', '-A'])['git', 'commit', '-m', msg])
if push:['git', 'push', remote, branch])
print("... skipped, dry run")
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--path', required=True,
help='path to code directory, containins .tx/config file')
parser.add_argument('--commit', action='store_true',
help='Make a local commit of fetched translations')
parser.add_argument('--push', action='store_true',
help='Push local commit to remote')
args = parser.parse_args()
if (args.push and not args.commit) or not os.path.isdir(args.path):
commit_translations(args.path, args.commit, args.push)