Make GitHub Actions check translation files (#534)
* validate_po.py: Fix typo "varialbes" * validate_po.py: Exit with code 1 on error * validate_po.py: Process locales in alphabetical order * validate_po.py: Report on progress * Make GitHub Actions check translation files
This commit is contained in:
parent
e6112a87a9
commit
dc0a470c34
|
@ -0,0 +1,31 @@
|
||||||
|
name: Check translations
|
||||||
|
|
||||||
|
# Drop permissions to minimum for security
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check_translations:
|
||||||
|
name: Check translations
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up Python 3.11
|
||||||
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: 3.11
|
||||||
|
|
||||||
|
- name: Install runtime dependencies
|
||||||
|
run: |
|
||||||
|
python3 -m pip install --upgrade pip setuptools wheel
|
||||||
|
python3 -m pip install polib
|
||||||
|
|
||||||
|
- name: Check translations
|
||||||
|
run: |
|
||||||
|
python3 validate_po.py
|
|
@ -19,17 +19,24 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import polib
|
import polib
|
||||||
|
import sys
|
||||||
|
|
||||||
def validate_po(locale, path):
|
def validate_po(locale: str, path: str) -> bool:
|
||||||
|
success = True
|
||||||
po = polib.pofile(path)
|
po = polib.pofile(path)
|
||||||
for entry in po:
|
for entry in po:
|
||||||
if entry.msgstr and (entry.msgid.count("%") != entry.msgstr.count("%")):
|
if entry.msgstr and (entry.msgid.count("%") != entry.msgstr.count("%")):
|
||||||
print("Number of varialbes mismatched in " + locale)
|
print("Number of variables mismatched in " + locale)
|
||||||
print(entry.msgid + " -> " + entry.msgstr)
|
print(entry.msgid + " -> " + entry.msgstr)
|
||||||
print()
|
print()
|
||||||
|
success = False
|
||||||
|
return success
|
||||||
|
|
||||||
|
success = True
|
||||||
locales = os.listdir('safeeyes/config/locale')
|
locales = os.listdir('safeeyes/config/locale')
|
||||||
for locale in locales:
|
for locale in sorted(locales):
|
||||||
path = os.path.join('safeeyes/config/locale', locale, "LC_MESSAGES/safeeyes.po")
|
path = os.path.join('safeeyes/config/locale', locale, "LC_MESSAGES/safeeyes.po")
|
||||||
if os.path.isfile(path):
|
if os.path.isfile(path):
|
||||||
validate_po(locale, path)
|
print('Validating translation %s...' % path)
|
||||||
|
success = validate_po(locale, path) and success
|
||||||
|
sys.exit(0 if success else 1)
|
||||||
|
|
Loading…
Reference in New Issue