Skip to content

Commit

Permalink
Merge commit from fork
Browse files Browse the repository at this point in the history
Co-authored-by: Omar Al-Ithawi <[email protected]>
  • Loading branch information
brian-smith-tcril and OmarIthawi authored Aug 23, 2024
1 parent 9204b88 commit b244434
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 "{कार्रवाई} एक वैध कार्रवाई नहीं है।"
35 changes: 31 additions & 4 deletions scripts/validate_translation_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import os.path
import subprocess
import sys
import textwrap

import i18n.validate

def get_translation_files(translation_directory):
"""
Expand All @@ -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,
}


Expand Down

0 comments on commit b244434

Please sign in to comment.