Update Crowdin locales manifest #10
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
name: Update Crowdin locales manifest | |
on: | |
push: | |
branches: | |
- master | |
paths: | |
- "public/locales/*" | |
workflow_dispatch: | |
branches: | |
- master | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions/setup-python@v2 | |
- name: Compute new manifest | |
run: | | |
import os | |
import time | |
import json | |
languages = [] | |
for i in os.listdir('public/locales'): | |
if os.path.isdir(os.path.join('public/locales',i)): | |
languages.append(i) | |
# Start with a default in case there is no file found | |
old = {"files":["\/lang.json"],"languages":["en"],"language_mapping":[],"custom_languages":[]} | |
new = {} | |
if os.path.exists("public/locales/manifest.json"): | |
with open("public/locales/manifest.json") as f: | |
old = json.load(f) | |
# Timestamp is not part of the keys we want to check for updates to | |
old.pop('timestamp',None) | |
# Carry over any keys that aren't being changed | |
new.update(old) | |
new['languages'] = languages | |
if not old==new: | |
new['timestamp'] = int(time.time()) | |
with open("public/locales/manifest.json", 'w') as f: | |
json.dump(new,f) | |
shell: python | |
- uses: peter-evans/create-pull-request@v3 | |
with: | |
commit-message: "Auto-update Crowdin manifest.json on changes to public/locales" | |
title: "Update locales manifest" |