Skip to content

Commit 3299c82

Browse files
author
Maciej Olko
committed
Add GitHub Action with updating translation
1 parent a07bba7 commit 3299c82

3 files changed

Lines changed: 39 additions & 5 deletions

File tree

.github/workflows/.transifexrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[https://www.transifex.com]
2+
api_hostname = https://api.transifex.com
3+
hostname = https://www.transifex.com
4+
username = api

.github/workflows/update.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
on:
2+
schedule:
3+
- cron: '0 0 * * *'
4+
push:
5+
branches:
6+
- '*'
7+
jobs:
8+
update:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v1
12+
- uses: actions/setup-python@v1
13+
with:
14+
python-version: 3.7
15+
- run: sudo apt-get install -y gettext
16+
- run: pip install transifex-client
17+
- run: cp .github/workflows/.transifexrc $HOME
18+
- run: ./manage_translations.py fetch
19+
env:
20+
TX_TOKEN: ${{ secrets.TX_TOKEN }}
21+
- run: git config --local user.email 'maciej.olko@gmail.com'
22+
- run: git config --local user.name 'Maciej Olko'
23+
- run: git commit -a -m 'Update translation from Transifex' || true
24+
- uses: ad-m/github-push-action@master
25+
with:
26+
github_token: ${{ secrets.GITHUB_TOKEN }}
27+
branch: 3.8

manage_translations.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
from argparse import ArgumentParser
1717
from subprocess import call
1818

19-
from numpy import average
20-
import requests
21-
2219
LANGUAGE = 'pl'
2320

2421

@@ -30,7 +27,10 @@ def fetch():
3027
sys.stderr.write("The Transifex client app is required (pip install transifex-client).\n")
3128
exit(1)
3229
lang = LANGUAGE
33-
call(f'tx pull -l {lang} --minimum-perc=25', shell=True)
30+
if os.getenv('GITHUB_ACTIONS'):
31+
call(f'tx pull -l {lang} --minimum-perc=25 --force', shell=True)
32+
else:
33+
call(f'tx pull -l {lang} --minimum-perc=25', shell=True)
3434
for root, _, po_files in os.walk('.'):
3535
for po_file in po_files:
3636
if not po_file.endswith(".po"):
@@ -79,12 +79,13 @@ def recreate_tx_config():
7979

8080

8181
def _get_resources():
82+
from requests import get
8283
resources = []
8384
offset = 0
8485
with open('.tx/api-key') as f:
8586
transifex_api_key = f.read()
8687
while True:
87-
response = requests.get(
88+
response = get(
8889
f'https://api.transifex.com/organizations/python-doc/projects/{PROJECT_SLUG}/resources/',
8990
params={'language_code': LANGUAGE, 'offset': offset},
9091
auth=('api', transifex_api_key))
@@ -97,6 +98,8 @@ def _get_resources():
9798

9899

99100
def recreate_readme():
101+
from numpy import average
102+
100103
def language_switcher(entry):
101104
return (entry['name'].startswith('bugs') or
102105
entry['name'].startswith('tutorial') or

0 commit comments

Comments
 (0)