-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: Update translations | ||
|
||
on: | ||
schedule: | ||
- cron: "0 */12 * * *" | ||
workflow_dispatch: | ||
|
||
jobs: | ||
update-translations: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
pull-requests: write | ||
env: | ||
CROWDIN_API: ${{ secrets.CROWDIN_API }} | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.11 | ||
- name: Run Python script | ||
run: python update.py | ||
working-directory: ./chameleonultragui/lib/l10n | ||
- name: Check for changes | ||
id: git-check | ||
run: | | ||
git config user.email "[email protected]" | ||
git config user.name "GitHub Actions" | ||
git add chameleonultragui/lib/l10n/* | ||
if [[ -z $(git status --untracked-files=no -s) ]]; then | ||
echo "No changes" | ||
else | ||
echo "::set-output name=has_changes::true" | ||
fi | ||
- name: Create commit | ||
uses: stefanzweifel/git-auto-commit-action@v4 | ||
if: steps.git-check.outputs.has_changes == 'true' | ||
with: | ||
commit_message: Update translations | ||
branch: translations-branch | ||
commit_options: '--no-verify' | ||
status_options: '--untracked-files=no' | ||
add_options: '-u' | ||
push_options: '--force' | ||
skip_dirty_check: true | ||
skip_fetch: true | ||
skip_checkout: true | ||
disable_globbing: true | ||
create_branch: true | ||
- name: Create PR | ||
if: steps.git-check.outputs.has_changes == 'true' | ||
uses: peter-evans/create-pull-request@v4 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
base: main | ||
branch: translations-branch | ||
commit-message: "New translations fetched from Crowdin" | ||
title: "feat: Update translations" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import json | ||
import os | ||
import sys | ||
import urllib.error | ||
from urllib.request import Request, urlopen | ||
|
||
|
||
def progressbar(it, prefix="", size=60, out=sys.stdout): | ||
count = len(it) | ||
|
||
def show(j): | ||
x = int(size * j / count) | ||
print(f"{prefix}[{u'█' * x}{('.' * (size - x))}] {j}/{count}", end='\r', file=out, flush=True) | ||
|
||
show(0) | ||
for i, item in enumerate(it): | ||
yield item | ||
show(i + 1) | ||
print("\n", flush=True, file=out) | ||
|
||
|
||
def request(method, url, data=None): | ||
if not data: | ||
data = {} | ||
return json.loads(urlopen(Request(url, method=method, data=json.dumps(data).encode(), | ||
headers={'Accept': 'application/json', | ||
'Authorization': 'Bearer ' + os.getenv('CROWDIN_API'), | ||
'Content-Type': 'application/json'})).read().decode()) | ||
|
||
|
||
for language in progressbar(request('GET', 'https://crowdin.com/api/v2/languages?limit=500')['data']): | ||
try: | ||
progress = request('GET', | ||
f'https://crowdin.com/api/v2/projects/610545/languages/{language["data"]["id"]}/progress') | ||
except urllib.error.HTTPError: | ||
continue | ||
if progress['data'][0]['data']['words']['translated']: | ||
translation = request("POST", "https://crowdin.com/api/v2/projects/610545/translations/exports", | ||
{"targetLanguageId": language["data"]["id"], "format": "arb-export", | ||
"skipUntranslatedStrings": True, "fileIds": [9]}) | ||
export = urlopen(Request(translation['data']['url'], method='GET')).read() | ||
open(f"app_{language['data']['osxLocale']}.arb", "wb+").write(export) |