Skip to content

Commit 09569dc

Browse files
committed
Add pull/push workflow for translations
- add cleanup.py for re-arranging po files - push translation for pushing sources to crowdin on pull request when rst is changed - add pull-translation.yml for getting translations from crowdin on demand when translation is ready Closes #104
1 parent 3d058b1 commit 09569dc

File tree

11 files changed

+1098
-0
lines changed

11 files changed

+1098
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Destroy-deployments
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'doc/**/*'
7+
types:
8+
- closed
9+
jobs:
10+
destroy-deployment:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
with:
15+
token: "${{ secrets.GITHUB_TOKEN }}"
16+
17+
- name: Set branch name from source branch
18+
run: echo "BRANCH_NAME=${GITHUB_HEAD_REF##*/}" >> $GITHUB_ENV
19+
20+
- name: Remove dev server deployment at ${{env.DEPLOYMENT_NAME}}
21+
uses: strumwolf/delete-deployment-environment@v2
22+
with:
23+
token: "${{ secrets.TARANTOOLBOT_TOKEN }}"
24+
environment: "translation-${{env.BRANCH_NAME}}"
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Pull translations
2+
3+
on:
4+
workflow_dispatch:
5+
branches:
6+
- '!master'
7+
jobs:
8+
pull-translations:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v2
13+
with:
14+
token: ${{secrets.TARANTOOLBOT_TOKEN}}
15+
16+
- name: Set branch name from source branch
17+
run: echo "BRANCH_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV
18+
19+
- name: Setup Python environment
20+
uses: actions/setup-python@v2
21+
22+
- name: Setup Python requirements
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install -r doc/requirements.txt
26+
27+
- name: Pull translations from Crowdin
28+
uses: crowdin/github-action@1.0.21
29+
with:
30+
config: 'doc/crowdin.yaml'
31+
upload_sources: false
32+
upload_translations: false
33+
push_translations: false
34+
download_translations: true
35+
download_language: 'ru'
36+
crowdin_branch_name: ${{env.BRANCH_NAME}}
37+
debug_mode: true
38+
env:
39+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
40+
CROWDIN_PERSONAL_TOKEN: ${{secrets.CROWDIN_PERSONAL_TOKEN}}
41+
42+
- name: Cleanup translation files
43+
run: |
44+
sudo chown -R runner:docker doc/locale/ru/LC_MESSAGES
45+
python doc/cleanup.py po
46+
47+
- name: Commit translation files
48+
uses: stefanzweifel/git-auto-commit-action@v4.1.2
49+
with:
50+
commit_message: "Update translations"
51+
file_pattern: "*.po"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Push translation sources
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'doc/**/*.rst'
7+
- 'doc/conf.py'
8+
- '.github/workflows/push-translation.yml'
9+
jobs:
10+
push-translation-sources:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
16+
- name: Set branch name from source branch
17+
run: echo "BRANCH_NAME=${GITHUB_HEAD_REF##*/}" >> $GITHUB_ENV
18+
19+
- name: Start translation service deployment
20+
uses: bobheadxi/deployments@v0.5.2
21+
id: translation
22+
with:
23+
step: start
24+
token: ${{secrets.GITHUB_TOKEN}}
25+
env: translation-${{env.BRANCH_NAME}}
26+
ref: ${{github.head_ref}}
27+
28+
- name: Setup Python environment
29+
uses: actions/setup-python@v2
30+
31+
- name: Setup Python requirements
32+
run: |
33+
python -m pip install --upgrade pip
34+
pip install -r doc/requirements.txt
35+
36+
- name: Build pot files
37+
run: python -m sphinx . doc/locale/en -c doc -b gettext
38+
39+
- name: Push POT files to crowdin
40+
uses: crowdin/github-action@1.0.21
41+
with:
42+
upload_sources: true
43+
upload_translations: false
44+
crowdin_branch_name: ${{env.BRANCH_NAME}}
45+
config: 'doc/crowdin.yaml'
46+
env:
47+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
48+
CROWDIN_PERSONAL_TOKEN: ${{secrets.CROWDIN_PERSONAL_TOKEN}}
49+
50+
- name: update deployment status
51+
uses: bobheadxi/deployments@v0.5.2
52+
with:
53+
step: finish
54+
token: ${{secrets.GITHUB_TOKEN}}
55+
status: ${{job.status}}
56+
deployment_id: ${{steps.translation.outputs.deployment_id}}
57+
env_url: https://crowdin.com/project/tarantool-cartridge-cli/ru#/${{env.BRANCH_NAME}}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Update translations on the main branch
2+
3+
on:
4+
push:
5+
paths:
6+
- 'doc/**/*.rst'
7+
- 'doc/locale/**/*.po'
8+
- '.github/workflows/upload-translations.yml'
9+
branches:
10+
- master
11+
jobs:
12+
autocommit-pot-files:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
17+
- name: Checkout
18+
uses: actions/checkout@v2
19+
20+
- name: Setup Python environment
21+
uses: actions/setup-python@v2
22+
23+
- name: Setup Python requirements
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install -r doc/requirements.txt
27+
28+
- name: Build pot files
29+
run: python -m sphinx . doc/locale/en -c doc -b gettext
30+
31+
- name: Push Pot-files to crowdin
32+
uses: crowdin/github-action@1.1.0
33+
with:
34+
config: 'doc/crowdin.yaml'
35+
upload_sources: true
36+
upload_translations: true
37+
import_eq_suggestions: true
38+
env:
39+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
40+
CROWDIN_PERSONAL_TOKEN: ${{secrets.CROWDIN_PERSONAL_TOKEN}}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,6 @@ deploy/*
8585

8686
ci/helm-chart/templates/crds/tarantool.io_*s_crd.yaml
8787
ci/helm-chart/templates/crds/tarantool_*_cr.yaml
88+
89+
doc/locale/en/
90+
doc/output/

doc/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[![Crowdin](https://badges.crowdin.net/tarantool-operator/localized.svg)](https://crowdin.com/project/tarantool-operator)
2+
3+
# Tarantool Kubernetes Operator documentation
4+
Part of Tarantool documentation, published to
5+
https://www.tarantool.io/en/doc/latest/book/cartridge/cartridge_kubernetes_guide/
6+
7+
## Create pot files from rst
8+
```bash
9+
python -m sphinx doc doc/locale/en -c doc -b gettext
10+
```
11+
12+
## Create/update po from pot files
13+
```bash
14+
sphinx-intl update -p doc/locale/en -d doc/locale -l ru
15+
```
16+
17+
## Build documentation to doc/output
18+
```bash
19+
python -m sphinx doc doc/output -c doc
20+
```

doc/cleanup.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#! /usr/bin/env python3
2+
import argparse
3+
from glob import glob
4+
from polib import pofile, POFile, _BaseFile
5+
6+
parser = argparse.ArgumentParser(description='Cleanup PO and POT files')
7+
parser.add_argument('extension', type=str, choices=['po', 'pot', 'both'],
8+
help='cleanup files with extension: po, pot or both')
9+
10+
11+
class PoFile(POFile):
12+
13+
def __unicode__(self):
14+
return _BaseFile.__unicode__(self)
15+
16+
def metadata_as_entry(self):
17+
class M:
18+
def __unicode__(self, _):
19+
return ''
20+
return M()
21+
22+
23+
def cleanup_files(extension):
24+
mask = f'**/*.{extension}'
25+
for file_path in glob(mask, recursive=True):
26+
print(f'cleanup {file_path}')
27+
po_file: POFile = pofile(file_path, klass=PoFile)
28+
po_file.header = ''
29+
po_file.metadata = {}
30+
po_file.metadata_is_fuzzy = False
31+
32+
for item in po_file:
33+
item.occurrences = None
34+
35+
po_file.save()
36+
37+
38+
if __name__ == "__main__":
39+
40+
args = parser.parse_args()
41+
42+
if args.extension in ['po', 'both']:
43+
cleanup_files('po')
44+
45+
if args.extension in ['pot', 'both']:
46+
cleanup_files('pot')

doc/conf.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import sys
2+
import os
3+
4+
sys.path.insert(0, os.path.abspath(''))
5+
6+
master_doc = 'doc/cartridge_kubernetes_guide/index'
7+
8+
source_suffix = '.rst'
9+
10+
project = u'Tarantool-operator'
11+
12+
exclude_patterns = [
13+
'doc/locale',
14+
'doc/output',
15+
'doc/README.md',
16+
'doc/cleanup.py',
17+
'doc/requirements.txt',
18+
]
19+
20+
language = 'en'
21+
locale_dirs = ['./doc/locale']
22+
gettext_compact = False
23+
gettext_location = True

doc/crowdin.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# https://support.crowdin.com/configuration-file/
2+
# https://support.crowdin.com/cli-tool-v3/#configuration
3+
4+
"project_id" : "463364"
5+
"base_path" : "doc/locale"
6+
"base_url": "https://crowdin.com"
7+
"api_token_env": "CROWDIN_PERSONAL_TOKEN"
8+
9+
10+
"preserve_hierarchy": true
11+
12+
files: [
13+
{
14+
"source" : "/en/**/*.pot",
15+
"translation" : "/%locale_with_underscore%/LC_MESSAGES/**/%file_name%.po",
16+
"update_option" : "update_as_unapproved",
17+
18+
"languages_mapping" : {
19+
"locale_with_underscore" : {
20+
"ru" : "ru",
21+
}
22+
},
23+
}
24+
]

0 commit comments

Comments
 (0)