Skip to content

Add a job to automatically update translations #1769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/list_languages
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3

import argparse
import json
import os
from pathlib import Path


def parse_langs(langs, include_beta):
for line in langs.readlines():
description = line[3:-7]
code = line[-5:-3]

if code != 'en' and (include_beta or 'beta' not in description):
yield code, description

def main():
parser = argparse.ArgumentParser()
parser.add_argument('--include-beta', help='Include beta languages', default='false',
choices=('true', 'false'))
parser.add_argument('--langs-file', help='LANGS.md to use',
type=argparse.FileType('r', encoding='UTF-8'),
default=(Path(__file__).absolute().parent.parent / 'LANGS.md').as_posix())
args = parser.parse_args()

languages = dict(parse_langs(args.langs_file, args.include_beta == 'true'))

if 'GITHUB_ACTION' in os.environ:
print(f'::set-output name=languages::{json.dumps(list(languages.keys()))}')
for code, language in languages.items():
print(f'{language} ({code})')


if __name__ == '__main__':
main()
54 changes: 54 additions & 0 deletions .github/workflows/translations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Update translations

on:
workflow_dispatch:
inputs:
include_beta:
type: boolean
default: false
description: Include beta languages

env:
GIT_AUTHOR_NAME: Django Girls Automation
GIT_AUTHOR_EMAIL: [email protected]

jobs:
list_languages:
name: List languages
runs-on: ubuntu-latest
outputs:
languages: ${{ steps.set_list.outputs.languages }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set the language list
id: set_list
run: ./.github/list_languages --include-beta ${{ inputs.include_beta }}

update_language:
name: 'Update ${{ matrix.language }} translations from Crowdin'
needs: list_languages
if: ${{ needs.list_languages.outputs.languages != '[]' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
language: ${{ fromJson(needs.list_languages.outputs.languages) }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Update language
run: |
wget https://crowdin.com/backend/download/project/django-girls-tutorial/${{ matrix.language }}.zip
unzip ${{ matrix.language }}.zip
find ${{ matrix.language }} -name '*.md' -delete
rsync -av master/${{ matrix.language }}*/* ${{ matrix.language }}/
rm -rf ${{ matrix.language }}.zip master
- name: Open a PR
uses: peter-evans/create-pull-request@v3
with:
commit-message: "Update ${{ matrix.language }} translations from Crowdin"
branch: "update_translations/${{ matrix.language }}"
title: "Update ${{ matrix.language }} translations from Crowdin"
body: ''
delete-branch: true
Comment on lines +47 to +54
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this removes any commits in update_translations and rebases it back to master. So this isn't good if you want to work on the branch.