Browse Source
Auto fix i18n strings (#262)
* Fix inaccurate comment
* Automatic PR base language string fixes
pull/265/head
Jonathan Wright
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
29 additions and
16 deletions
-
.github/workflows/publish.yml
-
find_missing_i18n_strings.py
|
|
@ -7,6 +7,7 @@ jobs: |
|
|
|
publish: |
|
|
|
runs-on: ubuntu-latest |
|
|
|
permissions: |
|
|
|
pull-requests: write |
|
|
|
contents: read |
|
|
|
deployments: write |
|
|
|
name: Publish to Cloudflare Pages |
|
|
@ -26,6 +27,21 @@ jobs: |
|
|
|
- name: Generate language files |
|
|
|
run: python3 setup-pages-for-supported-languages.py |
|
|
|
|
|
|
|
- name: Create Pull Request for i18n string changes |
|
|
|
uses: peter-evans/create-pull-request@v5 |
|
|
|
with: |
|
|
|
add-paths: i18n/en.json |
|
|
|
title: Automagic i18n string updates |
|
|
|
commit-message: Automagic i18n string updates |
|
|
|
branch-suffix: short-commit-hash |
|
|
|
delete-branch: true |
|
|
|
body: | |
|
|
|
Changes generated by find_missing_i18n_strings.py |
|
|
|
|
|
|
|
OP#217 |
|
|
|
|
|
|
|
Automated changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action |
|
|
|
|
|
|
|
- name: Build |
|
|
|
run: hugo --minify |
|
|
|
|
|
|
|
|
|
@ -27,23 +27,20 @@ for folder, dirs, files in os.walk(rootdir): |
|
|
|
error = True |
|
|
|
print(f'TRANSLATION ERROR: {string}') |
|
|
|
missing_keys[string] = '' |
|
|
|
en[string] = string # Add the missing key to the dictionary with an empty value |
|
|
|
print(f"Adding '{string}'") |
|
|
|
en[string] = string # Add the missing key to the dictionary |
|
|
|
elif string in unused_keys: |
|
|
|
unused_keys.remove(string) |
|
|
|
|
|
|
|
# If there are missing keys, dump the updated dictionary back into the json file |
|
|
|
if error: |
|
|
|
print(json.dumps(missing_keys, indent=3)) |
|
|
|
with open('i18n/en.json', 'w') as f: |
|
|
|
json.dump(en, f, indent=3) |
|
|
|
exit(1) |
|
|
|
|
|
|
|
# If there are unused keys, print them |
|
|
|
# TODO: Do something useful? |
|
|
|
if unused_keys: |
|
|
|
print("UNUSED KEYS:") |
|
|
|
if error or unused_keys: |
|
|
|
# Remove unused keys |
|
|
|
if unused_keys: |
|
|
|
for key in unused_keys: |
|
|
|
print(key) |
|
|
|
else: |
|
|
|
print(f"Removing '{key}'") |
|
|
|
del en[key] |
|
|
|
else: |
|
|
|
print("No unused keys found.") |
|
|
|
|
|
|
|
with open('i18n/en.json', 'w') as f: |
|
|
|
json.dump(en, f, indent=3) |
|
|
|