diff --git a/scripts/tests/mock_translations_dir/demo-xblock/conf/locale/hi/LC_MESSAGES/django.po b/scripts/tests/mock_translations_dir/demo-xblock/conf/locale/hi/LC_MESSAGES/django.po index 87b04909901..479c001fed4 100644 --- a/scripts/tests/mock_translations_dir/demo-xblock/conf/locale/hi/LC_MESSAGES/django.po +++ b/scripts/tests/mock_translations_dir/demo-xblock/conf/locale/hi/LC_MESSAGES/django.po @@ -13,6 +13,7 @@ msgstr "" "Plural-Forms: nplurals=2; plural=(n != 1);\n" "Generated-By: Babel 2.8.0\n" +# Translation has invalid brace-format with encoding errors #, python-brace-format msgid "{action} is not a valid action." -msgstr "{कार्रवाई} एक वैध कार्रवाई नहीं है।" # Invalid brace-format with encoding errors +msgstr "{कार्रवाई} एक वैध कार्रवाई नहीं है।" diff --git a/scripts/validate_translation_files.py b/scripts/validate_translation_files.py index e9d98e4f660..da7c9120a0f 100644 --- a/scripts/validate_translation_files.py +++ b/scripts/validate_translation_files.py @@ -7,7 +7,9 @@ import os.path import subprocess import sys +import textwrap +import i18n.validate def get_translation_files(translation_directory): """ @@ -29,18 +31,43 @@ def validate_translation_file(po_file): This function combines both stderr and stdout output of the `msgfmt` in a single variable. """ + valid = True + output = "" + completed_process = subprocess.run( ['msgfmt', '-v', '--strict', '--check', po_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) - stdout = completed_process.stdout.decode(encoding='utf-8', errors='replace') - stderr = completed_process.stderr.decode(encoding='utf-8', errors='replace') + if completed_process.returncode != 0: + valid = False + + msgfmt_stdout = completed_process.stdout.decode(encoding='utf-8', errors='replace') + msgfmt_stderr = completed_process.stderr.decode(encoding='utf-8', errors='replace') + output += f'{msgfmt_stdout}\n{msgfmt_stderr}\n' + + try: + problems = i18n.validate.check_messages(po_file) + except Exception as e: + output += f'{e} {traceback.format_exc()}' + valid = False + problems = [] + if problems: + valid = False + + id_filler = textwrap.TextWrapper(width=79, initial_indent=" msgid: ", subsequent_indent=" " * 9) + tx_filler = textwrap.TextWrapper(width=79, initial_indent=" -----> ", subsequent_indent=" " * 9) + for problem in problems: + desc, msgid = problem[:2] + output += f"{desc}\n{id_filler.fill(msgid)}\n" + for translation in problem[2:]: + output += f"{tx_filler.fill(translation)}\n" + output += "\n" return { - 'valid': completed_process.returncode == 0, - 'output': f'{stdout}\n{stderr}', + 'valid': valid, + 'output': output, }