Skip to content

Commit

Permalink
Auto fix i18n strings (#262)
Browse files Browse the repository at this point in the history
* Fix inaccurate comment
* Automatic PR base language string fixes
  • Loading branch information
jonathanspw authored Jul 23, 2023
1 parent 54491ab commit 027732b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ jobs:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
projectName: ${{ vars.CLOUDFLARE_PROJECT_NAME }}
directory: public
directory: public
16 changes: 16 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ jobs:
publish:
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: read
deployments: write
name: Publish to Cloudflare Pages
Expand All @@ -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

Expand Down
27 changes: 12 additions & 15 deletions find_missing_i18n_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,20 @@
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:")
for key in unused_keys:
print(key)
else:
print("No unused keys found.")
if error or unused_keys:
# Remove unused keys
if unused_keys:
for key in unused_keys:
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)

0 comments on commit 027732b

Please sign in to comment.