add a way to autofix weblate's issue with @string

This commit is contained in:
Cloudburst 2023-03-14 18:50:13 +00:00
parent 2d7126d71f
commit 7bfcf25df4
2 changed files with 20 additions and 4 deletions

13
.github/locales.py vendored
View file

@ -1,6 +1,7 @@
import re import re
import glob import glob
import requests import requests
import lxml.etree as ET # builtin library doesn't preserve comments
SETTINGS_PATH = "app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsGeneral.kt" SETTINGS_PATH = "app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsGeneral.kt"
@ -46,3 +47,15 @@ open(SETTINGS_PATH, "w+",encoding='utf-8').write(
END_MARKER + END_MARKER +
after_src after_src
) )
# Go through each values.xml file and fix escaped \@string
for file in glob.glob(f"{XML_NAME}*/strings.xml"):
try:
tree = ET.parse(file)
for child in tree.getroot():
if child.text.startswith("\\@string/"):
print(f"[{file}] fixing {child.attrib['name']}")
child.text = child.text.replace("\\@string/", "@string/")
tree.write(file, encoding="utf-8", method="xml", pretty_print=True, xml_declaration=True)
except ET.ParseError as ex:
print(f"[{file}] {ex}")

View file

@ -1,4 +1,4 @@
name: Update locale lists name: Fix locale issues
on: on:
workflow_dispatch: workflow_dispatch:
@ -9,7 +9,7 @@ on:
- master - master
concurrency: concurrency:
group: "locale-list" group: "locale"
cancel-in-progress: true cancel-in-progress: true
jobs: jobs:
@ -26,6 +26,9 @@ jobs:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
with: with:
token: ${{ steps.generate_token.outputs.token }} token: ${{ steps.generate_token.outputs.token }}
- name: Install dependencies
run: |
pip3 install lxml
- name: Edit files - name: Edit files
run: | run: |
python3 .github/locales.py python3 .github/locales.py
@ -35,5 +38,5 @@ jobs:
git config --local user.name "recloudstream[bot]" git config --local user.name "recloudstream[bot]"
git add . git add .
# "echo" returns true so the build succeeds, even if no changed files # "echo" returns true so the build succeeds, even if no changed files
git commit -m 'update list of locales' || echo git commit -m 'chore(locales): fix locale issues' || echo
git push git push