diff --git a/.github/workflows/translations_sanitycheck.yml b/.github/workflows/translations_sanitycheck.yml new file mode 100644 index 00000000..f30ab923 --- /dev/null +++ b/.github/workflows/translations_sanitycheck.yml @@ -0,0 +1,29 @@ +name: Sanity check translation phrases +on: + push: + branches: + - master + paths: + - 'translations/**' + pull_request: + branches: + - master + paths: + - 'translations/**' + workflow_dispatch: +jobs: + check_translations: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-python@v4 + name: Setup Python 3.10 + with: + python-version: "3.10" + + - name: Check translation phrases syntax + working-directory: tools/language_check + run: | + python ./sanity_check.py + diff --git a/tools/language_check/sanity_check.py b/tools/language_check/sanity_check.py new file mode 100644 index 00000000..7a36dcaf --- /dev/null +++ b/tools/language_check/sanity_check.py @@ -0,0 +1,42 @@ +#!/usr/bin/python3 +# Copyright (c) 2023 Peace-Maker +import pathlib +from smc_parser import smc_string_to_dict + +# Parse the languages.cfg file to know which languages could be available +had_problem = False +file_count = 0 +languages_cfg = smc_string_to_dict( + pathlib.Path('../../configs/languages.cfg').read_text('utf-8')) +print(f'Checking {len(languages_cfg["Languages"][0])} languages...') + +# Try to parse all the files as a simple smoke test for syntax errors +for langid, lang in languages_cfg['Languages'][0].items(): + if langid == 'en': + path = '../../translations' + else: + path = f'../../translations/{langid}' + + for file in pathlib.Path(path).glob('*.txt'): + if not file.is_file(): + continue + + file_count += 1 + try: + phrases = smc_string_to_dict(file.read_text('utf-8')) + if 'Phrases' not in phrases: + print( + f'Error in {langid}/{file.name}: File does not start with a "Phrases" section' + ) + had_problem = True + continue + except Exception as ex: + print(f'Error in {langid}/{file.name}: Error parsing: {ex}') + had_problem = True + continue + +print(f'Checked {file_count} files.') + +if had_problem: + print('Sanity check failed!') + exit(1)