Created
May 27, 2013 19:17
-
-
Save mtwebster/5658647 to your computer and use it in GitHub Desktop.
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)) | |
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 "Error: Number of tokens does not match: " | |
print entry.msgid, " ........ ", entry.msgstr | |
else: | |
for j in range(len(id_tokens)): | |
if id_tokens[j] != str_tokens[j]: | |
print "Error: tokens not in correct order: " | |
print entry.msgid, " ........ ", entry.msgstr | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment