Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_translated_messages(self, locale):
message_dir = LOCALE_DIR / locale / 'LC_MESSAGES'
for pofile_name in self.PO_FILES:
pofile_path = message_dir / pofile_name
pofile = polib.pofile(pofile_path)
mofile = polib.mofile(pofile_path.stripext() + '.mo')
po_entries = {entry.msgid: entry for entry in pofile.translated_entries()}
mo_entries = {entry.msgid: entry for entry in mofile.translated_entries()}
# Check that there are no entries in po that aren't in mo, and vice-versa
self.assertEquals(po_entries.viewkeys(), mo_entries.viewkeys())
for entry_id, po_entry in po_entries.items():
mo_entry = mo_entries[entry_id]
for attr in ('msgstr', 'msgid_plural', 'msgstr_plural', 'msgctxt', 'obsolete', 'encoding'):
po_attr = getattr(po_entry, attr)
mo_attr = getattr(mo_entry, attr)
# The msgstr_plural in the mo_file is keyed on ints, but in the po_file it's
# keyed on strings. This normalizes them.
if attr == 'msgstr_plural':
def load_files(self):
num_files = 0
for root, subFolders, files in os.walk(os.getcwd(),topdown=False):
for file in files:
if self.type == MO_EXT and file.endswith(MO_EXT):
num_files += 1
elif file.endswith(PO_EXT):
num_files += 1
count_files = 0
for root, subFolders, files in os.walk(os.getcwd(),topdown=False):
for file in files:
if self.type == MO_EXT and file.endswith(MO_EXT):
path, junk = os.path.split(root)
path, locale = os.path.split(path)
mo_inst = polib.mofile(os.path.join(root, file))
mo = Mo(mo_inst, locale, os.path.join(root, file))
elif file.endswith(PO_EXT):
mo_inst = polib.pofile(os.path.join(root, file))
mo = Mo(mo_inst, file, os.path.join(root, file))
if mo.locale in UNSUPPORTED_LOCALES:
# Don't check PO files for some of the locales (right-to-left languages for instance, or languages where it's hard for us to verify the arguments)
continue
else:
continue
count_files += 1
self.check_file(mo)
self.report_progress(count_files, num_files)