2021-10-14 16:05:36 +02:00
|
|
|
import re
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import polib
|
|
|
|
|
2022-02-14 14:25:00 +01:00
|
|
|
placeholder_regexp = re.compile(r"\{[^\}]*?\}")
|
2021-10-14 16:05:36 +02:00
|
|
|
|
2022-02-14 14:25:00 +01:00
|
|
|
for path in Path(__file__).parent.resolve().parent.rglob("LC_MESSAGES/*.po"):
|
2021-10-14 16:05:36 +02:00
|
|
|
po = polib.pofile(path)
|
|
|
|
for entry in po:
|
|
|
|
if not entry.msgstr:
|
|
|
|
continue # ignore untranslated strings
|
|
|
|
|
|
|
|
expected_placeholders = set(placeholder_regexp.findall(entry.msgid))
|
|
|
|
actual_placeholders = set(placeholder_regexp.findall(entry.msgstr))
|
|
|
|
if expected_placeholders != actual_placeholders:
|
2023-06-12 19:40:09 +02:00
|
|
|
print("Invalid string at %s line %d:" % (path, entry.linenum)) # noqa: T201
|
|
|
|
print( # noqa: T201
|
2022-02-14 14:25:00 +01:00
|
|
|
"\toriginal string %r has placeholders: %r"
|
|
|
|
% (entry.msgid, expected_placeholders)
|
2023-06-12 19:40:09 +02:00
|
|
|
)
|
|
|
|
print( # noqa: T201
|
2022-02-14 14:25:00 +01:00
|
|
|
"\ttranslated string %r has placeholders: %r"
|
|
|
|
% (entry.msgstr, actual_placeholders)
|
2023-06-12 19:40:09 +02:00
|
|
|
)
|
|
|
|
print() # noqa: T201
|