Translation: weblate integration

* after each commit on the master branch:
  check if searx/translations/messages.pot must be updated, if yes:
  * merge commits from weblate
  * build & commit the messages.mo files
  * update & commit messages.pot

* every Friday, the translations from weblate are commited into the master branch
This commit is contained in:
Alexandre Flament 2021-08-03 09:35:40 +02:00
parent 34ffd08187
commit ec4bacc1a8
3 changed files with 83 additions and 21 deletions

View file

@ -102,32 +102,24 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
with:
persist-credentials: false
fetch-depth: '0'
token: ${{ secrets.WEBLATE_GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
architecture: 'x64'
- name: weblate & git setup
env:
WEBLATE_CONFIG: ${{ secrets.WEBLATE_CONFIG }}
run: |
mkdir -p ~/.config
echo "${WEBLATE_CONFIG}" > ~/.config/weblate
git config --global user.email "alex.searxng@al-f.net"
git config --global user.name "searxng-bot"
- name: Update transations
id: update
continue-on-error: true
run: make V=1 ci.babel.update
- name: Open pull request
if: steps.update.outcome == 'success'
uses: peter-evans/create-pull-request@v3
with:
commit-message: Update translations (pot, po)
committer: searx-bot <noreply@github.com>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
signoff: false
branch: update_translations_pot
delete-branch: true
draft: false
title: 'Update translations (pot, po)'
body: |
Update messages.pot and messages.po files
labels: |
translation
dockers:
name: Docker

View file

@ -0,0 +1,34 @@
name: "Update translations (weblate)"
on:
schedule:
- cron: "05 07 * * 5"
workflow_dispatch:
jobs:
babel:
name: Weblate
runs-on: ubuntu-20.04
if: ${{ github.repository_owner == 'searxng' && github.ref == 'refs/heads/master' }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: '0'
token: ${{ secrets.WEBLATE_GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
architecture: 'x64'
- name: weblate & git setup
env:
WEBLATE_CONFIG: ${{ secrets.WEBLATE_CONFIG }}
run: |
mkdir -p ~/.config
echo "${WEBLATE_CONFIG}" > ~/.config/weblate
git config --global user.email "alex.searxng@al-f.net"
git config --global user.name "searxng-bot"
- name: Merge and push transation updates
id: update
run: make V=1 weblate.merge.push.updates

42
manage
View file

@ -126,6 +126,27 @@ babel.sha256sum() {
grep "msgid" "searx/translations/messages.pot" | sort | sha256sum | cut -f1 -d ' '
}
weblate.merge.push.updates() {
( set -e
pyenv.cmd wlc lock
if ! git remote get-url weblate; then
git remote add weblate https://weblate.bubu1.eu/git/searxng/searxng/
fi
git remote update weblate
git merge weblate/master
babel.compile
git add searx/translations
git commit -m "[translations] update messages.mo files"
git push
)
exitcode=$?
( # make sure to always unlock weblate
set -e
pyenv.cmd wlc unlock
)
dump_return $exitcode
}
ci.babel.update() {
local sha_before
( set -e
@ -133,12 +154,27 @@ ci.babel.update() {
babel.extract
if [ "$(babel.sha256sum)" = "${sha_before}" ]; then
build_msg BABEL 'no changes detected, exiting'
return 1
return 0
fi
# call weblate.merge.push.updates right away
git stash push "searx/translations/messages.pot"
weblate.merge.push.updates babel.update
# then update messages.pot while weblate is locked
pyenv.cmd wlc lock
git stash pop
babel.update
build_msg BABEL 'update done, edit .po files if required and run babel.compile'
git add searx/translations
git commit -m "[translations] update messages.pot and messages.po files"
git push
)
dump_return $?
exitcode=$?
( # make sure to always unlock weblate
set -e
pyenv.cmd wlc unlock
)
dump_return $exitcode
}
babel.extract() {