2011-06-30 13:30:42 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
2013-04-21 15:57:17 +02:00
|
|
|
import glob
|
2014-01-21 19:30:24 +01:00
|
|
|
import operator
|
2013-02-08 18:40:57 +01:00
|
|
|
import subprocess
|
2011-06-30 13:30:42 +02:00
|
|
|
|
2014-01-21 19:30:24 +01:00
|
|
|
from supybot.i18n import parse
|
|
|
|
|
2011-06-30 13:30:42 +02:00
|
|
|
def main():
|
|
|
|
directory = sys.argv[1]
|
2013-04-21 15:57:17 +02:00
|
|
|
if directory == '--core':
|
|
|
|
checkCore()
|
|
|
|
else:
|
|
|
|
for plugin in os.listdir(directory):
|
|
|
|
if plugin[0] not in 'AZERTYUIOPQSDFGHJKLMWXCVBN':
|
|
|
|
continue
|
|
|
|
checkPlugin(os.path.join(directory, plugin))
|
2011-06-30 13:30:42 +02:00
|
|
|
|
2013-02-08 18:40:57 +01:00
|
|
|
def changedir(f):
|
|
|
|
def newf(new_path):
|
|
|
|
old_path = os.getcwd()
|
|
|
|
os.chdir(new_path)
|
|
|
|
try:
|
|
|
|
return f('.')
|
|
|
|
finally:
|
|
|
|
os.chdir(old_path)
|
|
|
|
return newf
|
|
|
|
|
2013-04-21 15:57:17 +02:00
|
|
|
def checkCore():
|
|
|
|
_checkCore(os.path.join(os.path.dirname(__file__), '..'))
|
|
|
|
|
|
|
|
@changedir
|
|
|
|
def _checkCore(corePath):
|
|
|
|
subprocess.Popen(['pygettext', '-p', 'locales', 'plugins/__init__.py'] + glob.glob('src/*.py') + glob.glob('src/*/*.py')).wait()
|
|
|
|
localePath = os.path.join(corePath, 'locales')
|
|
|
|
pot = open(os.path.join(localePath, 'messages.pot'))
|
|
|
|
for translation in os.listdir(localePath):
|
|
|
|
if not translation.endswith('.po'):
|
|
|
|
continue
|
|
|
|
pot.seek(0)
|
|
|
|
potPath = os.path.join(os.getcwd(), 'locales', translation)
|
|
|
|
po = open(potPath)
|
|
|
|
if checkTranslation(pot, po):
|
|
|
|
print 'OK: ' + potPath
|
|
|
|
else:
|
|
|
|
print 'ERROR: ' + potPath
|
|
|
|
|
2013-02-08 18:40:57 +01:00
|
|
|
|
|
|
|
@changedir
|
2011-06-30 13:30:42 +02:00
|
|
|
def checkPlugin(pluginPath):
|
2013-02-08 18:40:57 +01:00
|
|
|
subprocess.Popen('pygettext -D config.py plugin.py', shell=True).wait()
|
|
|
|
pot = open(os.path.join(pluginPath, 'messages.pot'))
|
|
|
|
localePath = os.path.join(pluginPath, 'locales')
|
2011-06-30 13:30:42 +02:00
|
|
|
for translation in os.listdir(localePath):
|
|
|
|
if not translation.endswith('.po'):
|
|
|
|
continue
|
|
|
|
pot.seek(0)
|
2013-03-02 14:26:31 +01:00
|
|
|
potPath = os.path.join(os.getcwd(), 'locales', translation)
|
2011-06-30 13:30:42 +02:00
|
|
|
po = open(potPath)
|
|
|
|
if checkTranslation(pot, po):
|
|
|
|
print 'OK: ' + potPath
|
|
|
|
else:
|
|
|
|
print 'ERROR: ' + potPath
|
|
|
|
|
|
|
|
def checkTranslation(pot, po):
|
|
|
|
checking = False
|
2014-01-21 19:30:24 +01:00
|
|
|
pot = set(map(operator.itemgetter(0), parse(pot)))
|
|
|
|
po = set(map(operator.itemgetter(0), parse(po)))
|
|
|
|
diff = filter(lambda x:x not in po, pot)
|
|
|
|
print(diff)
|
|
|
|
return not bool(diff)
|
2011-06-30 13:30:42 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|