https://github.com/ProgVal/Limnoria
Raw File
Tip revision: d437aa0199dac94d7126665870f2d89041556fde authored by Valentin Lorentz on 18 August 2011, 10:17:45 UTC
Merge branch 'testing' into minecraft
Tip revision: d437aa0
check_trans.py
#!/usr/bin/env python

import os
import sys

def main():
    directory = sys.argv[1]
    for plugin in os.listdir(directory):
        if plugin[0] not in 'AZERTYUIOPQSDFGHJKLMWXCVBN':
            continue
        checkPlugin(os.path.join(directory, plugin))

def checkPlugin(pluginPath):
    try:
        pot = open(os.path.join(pluginPath, 'messages.pot'))
    except IOError: # Does not exist
        print 'WARNING: %s has no messages.pot' % pluginPath
        return
    localePath = os.path.join(pluginPath, 'locale')
    for translation in os.listdir(localePath):
        if not translation.endswith('.po'):
            continue
        pot.seek(0)
        potPath = os.path.join(localePath, translation)
        po = open(potPath)
        if checkTranslation(pot, po):
            print 'OK:      ' + potPath
        else:
            print 'ERROR:   ' + potPath

def checkTranslation(pot, po):
    checking = False
    for potLine in pot:
        if not checking and potLine.startswith('msgid'):
            checking = True
            while True:
                poLine = po.readline()
                if poLine == '': # EOF
                    return False
                if poLine.startswith('msgid'):
                    if poLine == potLine:
                        break
                    else:
                        return False
            continue
        elif checking and potLine.startswith('msgstr'):
            checking = False

        if checking:
            poLine = po.readline()
            if potLine != poLine:
                return False
    return True

if __name__ == '__main__':
    main()
back to top