|
| 1 | +import os |
| 2 | +import sys |
| 3 | + |
1 | 4 | from invoke import task
|
2 | 5 |
|
3 | 6 | DOCKER_COMPOSE = 'common/dockerfiles/docker-compose.yml'
|
@@ -158,3 +161,34 @@ def buildassets(c):
|
158 | 161 | """Build all assets for the application and push them to backend storage"""
|
159 | 162 | c.run(f'docker-compose -f {DOCKER_COMPOSE_ASSETS} run --rm assets bash -c "npm ci && node_modules/bower/bin/bower --allow-root update && npm run build"', pty=True)
|
160 | 163 | c.run(f'{DOCKER_COMPOSE_COMMAND} run --rm web python3 manage.py collectstatic --noinput', pty=True)
|
| 164 | + |
| 165 | + |
| 166 | +@task(help={ |
| 167 | + 'action': 'Action to realize on Transifex ("pull" or "push")', |
| 168 | +}) |
| 169 | +def translations(c, action): |
| 170 | + |
| 171 | + if action not in ('pull', 'push'): |
| 172 | + print(f'Action passed ("{action}") not supported. Use "pull" or "push".') |
| 173 | + sys.exit(1) |
| 174 | + |
| 175 | + transifex_token = os.environ.get('TRANSIFEX_TOKEN', None) |
| 176 | + if not transifex_token: |
| 177 | + print('You need to export TRANSIFEX_TOKEN environment variable.') |
| 178 | + sys.exit(1) |
| 179 | + |
| 180 | + |
| 181 | + # Download Transifex Client to be used from inside the container |
| 182 | + if not os.path.exists('tx'): |
| 183 | + download_file = 'https://github.com/transifex/cli/releases/download/v1.1.0/tx-linux-amd64.tar.gz' |
| 184 | + c.run(f'{DOCKER_COMPOSE_COMMAND} run --rm web /bin/bash -c "curl --location {download_file} | tar --extract -z --file=- tx"', pty=True) |
| 185 | + |
| 186 | + if action == 'pull': |
| 187 | + c.run(f'{DOCKER_COMPOSE_COMMAND} run --rm web ./tx --token {transifex_token} pull --force', pty=True) |
| 188 | + c.run(f'{DOCKER_COMPOSE_COMMAND} run --rm web /bin/bash -c "cd readthedocs/ && python3 ../manage.py makemessages --all"', pty=True) |
| 189 | + c.run(f'{DOCKER_COMPOSE_COMMAND} run --rm web /bin/bash -c "cd readthedocs/ && python3 ../manage.py compilemessages"', pty=True) |
| 190 | + |
| 191 | + elif action == 'push': |
| 192 | + c.run(f'{DOCKER_COMPOSE_COMMAND} run --rm web /bin/bash -c "cd readthedocs/ && python3 ../manage.py makemessages --locale en"', pty=True) |
| 193 | + c.run(f'{DOCKER_COMPOSE_COMMAND} run --rm web ./tx --token {transifex_token} push --source', pty=True) |
| 194 | + c.run(f'{DOCKER_COMPOSE_COMMAND} run --rm web /bin/bash -c "cd readthedocs/ && python3 ../manage.py compilemessages --locale en"', pty=True) |
0 commit comments