Skip to content

Commit

Permalink
Improve the validate_translations.py script.
Browse files Browse the repository at this point in the history
Without marking the regular expressions as raw strings Python emits the
following warning:

.../devilutionX/tools/validate_translations.py:24: SyntaxWarning: invalid escape sequence '\d'
  if re.search("^{\d+}$", argument) == None:
  • Loading branch information
nelchael committed Nov 10, 2024
1 parent 9d511f7 commit b3fe044
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions tools/validate_translations.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
#!/usr/bin/env python
#!/usr/bin/env python3

import re
from glob import glob

import polib
import re


def validateEntry(original, translation):
if translation == '':
return True

# Find fmt arguments in source message
src_arguments = re.findall("{.*?}", original)
if len(src_arguments) == 0:
src_arguments = re.findall(r"{.*?}", original)
if not src_arguments:
return True

# Find fmt arguments in translation
translated_arguments = re.findall("{.*?}", translation)
translated_arguments = re.findall(r"{.*?}", translation)

# If paramteres are untyped with order, sort so that they still appear equal if reordered
# Note: This does no hadle cases where the translator reordered arguments where not expected
# by the source. Or other advanced but valid usages of the fmt syntax
isOrdered = True
for argument in src_arguments:
if re.search("^{\d+}$", argument) == None:
if not re.search(r"^{\d+}$", argument):
isOrdered = False
break

Expand All @@ -32,18 +34,17 @@ def validateEntry(original, translation):
if src_arguments == translated_arguments:
return True

print ("\033[36m" + original + "\033[0m != \033[31m" + translation + "\033[0m")
print(f"\033[36m{original}\033[0m != \033[31m{translation}\033[0m")

return False


status = 0

files = glob('Translations/*.po')
files.sort()
for path in files:
for path in sorted(files):
po = polib.pofile(path)
print ("\033[32mValidating " + po.metadata['Language'] + "\033[0m : " + str(po.percent_translated()) + "% translated")
print(f"\033[32mValidating {po.metadata['Language']}\033[0m : {po.percent_translated()}% translated")

for entry in po:
if entry.fuzzy:
Expand Down

0 comments on commit b3fe044

Please sign in to comment.