-
-
Notifications
You must be signed in to change notification settings - Fork 3
Develop 4.3 #83
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
Merged
Merged
Develop 4.3 #83
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c094876
Refactor sorting logic in sort_en_xml.py to filter and sort <string> …
MightyMCoder 0e1778e
Refactor XML sorting logic to preserve comments and improve buffer ha…
MightyMCoder b27a5fd
Refactor commit logic in sort-en-xml.yml to streamline file handling …
MightyMCoder 2665c7b
Refactor workflow steps in sort-en-xml.yml to clarify script executio…
MightyMCoder 99ac8c7
chore: sort en.xml alphabetically
39fd638
Refactor sorting logic in sort_en_xml.py to simplify buffer handling …
MightyMCoder d7c742c
chore: sort en.xml alphabetically
d036934
fix language file sorting workflow
MightyMCoder ad1fbc3
feat: add workflow and script to check for unused translation keys
MightyMCoder b404f01
fix: correct script path in unused string checker workflow
MightyMCoder 6851f4d
fix: update unused string checker workflow to handle errors correctly
MightyMCoder ed972bf
fix: update workflows to ensure proper handling of unused strings and…
MightyMCoder 9350965
fix: remove error message from unused string checker command
MightyMCoder 7fddc85
fix: add debug output for event name and check outcome in unused stri…
MightyMCoder f92f52f
fix: update unused string checker workflow to annotate warnings for u…
MightyMCoder abca4a2
fix: update conditions for jq installation and PR review in unused st…
MightyMCoder ed54d69
fix: remove jq installation step from unused string checker workflow
MightyMCoder 247c5f6
fix: remove unused strings from language files
MightyMCoder 08ab037
fix: add approval step for PRs with no unused translation keys
MightyMCoder 1e067b4
Revert "fix: add approval step for PRs with no unused translation keys"
MightyMCoder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,30 @@ | ||
| import os, re, xml.etree.ElementTree as ET | ||
| import argparse | ||
|
|
||
| p = argparse.ArgumentParser() | ||
| p.add_argument('--exclude', default='', help='Comma‑separated dirs to skip') | ||
| args = p.parse_args() | ||
| excl = {d.strip() for d in args.exclude.split(',') if d.strip()} | ||
|
|
||
| root = ET.parse('languages/en.xml').getroot() | ||
| keys = [e.attrib['name'] for e in root.findall('.//string') | ||
| if re.fullmatch(r'[A-Z0-9_]+', e.attrib['name'])] | ||
|
|
||
| unused = [] | ||
| for k in keys: | ||
| used = False | ||
| for dp, _, fs in os.walk('.'): | ||
| if any(part in excl for part in dp.split(os.sep)): | ||
| continue | ||
| for f in fs: | ||
| if f.endswith(('.php','.js','.html','.tpl')): | ||
| if k in open(os.path.join(dp, f), 'r', errors='ignore').read(): | ||
| used = True; break | ||
| if used: break | ||
| if not used: | ||
| unused.append(k) | ||
|
|
||
| if unused: | ||
| for k in unused: | ||
| print(f"UNUSED: {k}") | ||
| exit(1) # triggers warning via continue-on-error | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,9 +1,38 @@ | ||
| import xml.etree.ElementTree as ET | ||
| from lxml import etree | ||
|
|
||
| file = 'languages/en.xml' | ||
| tree = ET.parse(file) | ||
|
|
||
| # Load XML with comments preserved | ||
| parser = etree.XMLParser(remove_blank_text=False) | ||
| tree = etree.parse(file, parser) | ||
| root = tree.getroot() | ||
| root[:] = sorted(root, key=lambda e: e.attrib.get('name','')) | ||
| ET.indent(tree, space=" ") | ||
| tree.write(file, encoding='utf-8', xml_declaration=True) | ||
|
|
||
| new_children = [] | ||
| buffer = [] | ||
|
|
||
| def flush_buffer(): | ||
| """Sort and add all <string> elements in the buffer.""" | ||
| if buffer: | ||
| sorted_strings = sorted(buffer, key=lambda e: e.attrib.get('name', '')) | ||
| new_children.extend(sorted_strings) | ||
| buffer.clear() | ||
|
|
||
| for elem in root.iterchildren(): | ||
| if isinstance(elem, etree._Comment): | ||
| flush_buffer() | ||
| new_children.append(elem) | ||
| elif elem.tag == 'string': | ||
| buffer.append(elem) | ||
| else: | ||
| flush_buffer() | ||
| new_children.append(elem) | ||
|
|
||
| # Flush anything left at the end | ||
| flush_buffer() | ||
|
|
||
| # Replace root content | ||
| root[:] = new_children | ||
|
|
||
| # Save result | ||
| tree.write(file, encoding='utf-8', xml_declaration=True, pretty_print=True) | ||
| print("en.xml successfully sorted.") |
This file contains hidden or 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,56 @@ | ||
| name: Check Unused Strings | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
| paths: | ||
| - languages/en.xml | ||
| pull_request: | ||
| branches: | ||
| - master | ||
| paths: | ||
| - languages/en.xml | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| unused-strings: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: '3.x' | ||
|
|
||
| - name: Run unused‑string checker | ||
| id: check | ||
| run: | | ||
| python .github/scripts/check_unused_strings.py --exclude .github > unused_keys.txt | ||
|
|
||
| - name: Annotate warning if unused | ||
| if: failure() | ||
| continue-on-error: true | ||
| run: | | ||
| echo "::warning file=en.xml::Detected unused translation keys. Please review." | ||
|
|
||
| - name: Post PR review with unused keys | ||
| if: ${{ github.event_name == 'pull_request' && failure() }} | ||
| continue-on-error: true | ||
| env: | ||
| GITHUB_TOKEN: ${{ github.token }} | ||
| run: | | ||
| PR_NUMBER=$(jq --raw-output .number "$GITHUB_EVENT_PATH") | ||
| BODY=$(echo -e "**WARNING: Unused translation keys detected**\n\n\`\`\`\n$(cat unused_keys.txt)\n\`\`\`\nPlease consider removing or using these keys." | jq -Rs .) | ||
|
|
||
| curl -s -X POST -H "Authorization: Bearer $GITHUB_TOKEN" \ | ||
| -H "Content-Type: application/json" \ | ||
| https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER/reviews \ | ||
| -d "{\"body\": $BODY, \"event\": \"REQUEST_CHANGES\"}" |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.