Skip to content

Commit 7bfcf25

Browse files
committed
add a way to autofix weblate's issue with @string
1 parent 2d7126d commit 7bfcf25

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

.github/locales.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import re
22
import glob
33
import requests
4+
import lxml.etree as ET # builtin library doesn't preserve comments
45

56

67
SETTINGS_PATH = "app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsGeneral.kt"
@@ -45,4 +46,16 @@
4546
"\n" +
4647
END_MARKER +
4748
after_src
48-
)
49+
)
50+
51+
# Go through each values.xml file and fix escaped \@string
52+
for file in glob.glob(f"{XML_NAME}*/strings.xml"):
53+
try:
54+
tree = ET.parse(file)
55+
for child in tree.getroot():
56+
if child.text.startswith("\\@string/"):
57+
print(f"[{file}] fixing {child.attrib['name']}")
58+
child.text = child.text.replace("\\@string/", "@string/")
59+
tree.write(file, encoding="utf-8", method="xml", pretty_print=True, xml_declaration=True)
60+
except ET.ParseError as ex:
61+
print(f"[{file}] {ex}")

.github/workflows/update_locales.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Update locale lists
1+
name: Fix locale issues
22

33
on:
44
workflow_dispatch:
@@ -9,7 +9,7 @@ on:
99
- master
1010

1111
concurrency:
12-
group: "locale-list"
12+
group: "locale"
1313
cancel-in-progress: true
1414

1515
jobs:
@@ -26,6 +26,9 @@ jobs:
2626
- uses: actions/checkout@v2
2727
with:
2828
token: ${{ steps.generate_token.outputs.token }}
29+
- name: Install dependencies
30+
run: |
31+
pip3 install lxml
2932
- name: Edit files
3033
run: |
3134
python3 .github/locales.py
@@ -35,5 +38,5 @@ jobs:
3538
git config --local user.name "recloudstream[bot]"
3639
git add .
3740
# "echo" returns true so the build succeeds, even if no changed files
38-
git commit -m 'update list of locales' || echo
41+
git commit -m 'chore(locales): fix locale issues' || echo
3942
git push

0 commit comments

Comments
 (0)