Skip to content

Commit 52595d9

Browse files
committed
Add cleaner for custom phrases
1 parent d5eb033 commit 52595d9

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

.github/workflows/cleaner.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Custom Cleaner
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
run-python-script:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: '3.x'
22+
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
27+
- name: Run cleaner.py
28+
run: python ./cleaner.py

CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,11 @@ In definitiva per partecipare a questo progetto bisogna:
9191
1. Creare un fork
9292
2. Effettua le modifiche
9393
3. Richiedi di integrare il tuo lavoro tramite pull request
94+
95+
## Workflows
96+
Abbiamo due workflow sulla repository:
97+
98+
- Validate: controlla che l'XML sia valido
99+
- Cleaner: rimuove ogni personalizzazione di traduzione, rimuovendo i `<phrase>` con `addon_id=""`
100+
101+
Non è necessaria alcuna operazione, i workflow vengono eseguiti automaticamente alla PR e alla Push

cleaner.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import xml.etree.ElementTree as ET
2+
3+
def remove_empty_phrases(xml_file):
4+
# Carica il file XML
5+
tree = ET.parse(xml_file)
6+
root = tree.getroot()
7+
8+
# Trova tutti i genitori che hanno una tag <phrase> con addon_id="" e rimuove tali <phrase>
9+
phrases_to_remove = root.findall(".//phrase[@addon_id='']")
10+
for phrase in phrases_to_remove:
11+
for parent in root.iter():
12+
if phrase in list(parent):
13+
parent.remove(phrase)
14+
15+
# Salva il file XML modificato
16+
tree.write(xml_file, encoding='utf-8', xml_declaration=True)
17+
18+
# Esempio di utilizzo
19+
if __name__ == "__main__":
20+
xml_file = './language-italiano.xml'
21+
remove_empty_phrases(xml_file)

0 commit comments

Comments
 (0)