Last active
December 17, 2015 19:09
-
-
Save mtwebster/5658660 to your computer and use it in GitHub Desktop.
Check locale dir for mo files, report back any where token counts don't match or token order doesn't match
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import polib | |
import sys | |
import os | |
tokentypes = ["%d", "%s", "%B", "%'d"] | |
for root, subFolders, files in os.walk(os.getcwd(),topdown=False): | |
for file in files: | |
if file.endswith(".mo"): | |
mo = polib.mofile(os.path.join(root, file)) | |
path, junk = os.path.split(root) | |
path, locale = os.path.split(path) | |
for entry in mo: | |
id_tokens = [] | |
str_tokens = [] | |
msgid = entry.msgid | |
msgstr = entry.msgstr | |
for idx in range(len(msgid)): | |
if msgid[idx] == "%": | |
for tt in tokentypes: | |
if msgid[idx:idx+len(tt)] == tt: | |
id_tokens.append(tt) | |
for idx in range(len(msgstr)): | |
if msgstr[idx] == "%": | |
for tt in tokentypes: | |
if msgstr[idx:idx+len(tt)] == tt: | |
str_tokens.append(tt) | |
if msgstr != "": | |
if (len(id_tokens) != len(str_tokens)): | |
print "%s: Error: Number of tokens does not match: " % (locale), entry.msgid, " ... ", entry.msgstr | |
else: | |
for j in range(len(id_tokens)): | |
if id_tokens[j] != str_tokens[j]: | |
print "%s: Error: tokens not in correct order: " % (locale), entry.msgid, " ... ", entry.msgstr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment