Skip to content

Commit b69771c

Browse files
authored
Merge pull request #147 from readthedocs/humitos/translations-task
Translations: define `inv docker.translations` task
2 parents 11bdabe + 28c51d4 commit b69771c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

dockerfiles/tasks.py

+34
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import os
2+
import sys
3+
14
from invoke import task
25

36
DOCKER_COMPOSE = 'common/dockerfiles/docker-compose.yml'
@@ -158,3 +161,34 @@ def buildassets(c):
158161
"""Build all assets for the application and push them to backend storage"""
159162
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)
160163
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

Comments
 (0)