Fix some unicode problems with the script.

This commit is contained in:
Michal Čihař
2010-06-03 14:46:59 +02:00
parent 5d525e89eb
commit 2ff0e610fc

View File

@@ -67,11 +67,9 @@ CODE2LANG = {
} }
if len(sys.argv) != 2: if len(sys.argv) != 2:
print 'Usage: update-from-po PATH_TO_PO_FILES' print 'Usage: update-from-po PO_FILES'
sys.exit(1) sys.exit(1)
pofiles = os.listdir(sys.argv[1])
f = file('lang/english-utf-8.inc.php', 'r') f = file('lang/english-utf-8.inc.php', 'r')
langmap = {} langmap = {}
for line in f: for line in f:
@@ -80,7 +78,8 @@ for line in f:
parts = line.split(' = ') parts = line.split(' = ')
langmap[parts[1].strip(';').strip('\'')] = parts[0].strip('$') langmap[parts[1].strip(';').strip('\'')] = parts[0].strip('$')
for pofile in pofiles: for pofile_full in sys.argv[1:]:
pofile = os.path.basename(pofile_full)
if pofile[-3:] != '.po': if pofile[-3:] != '.po':
print 'Not a po file, skipping: %s' % pofile print 'Not a po file, skipping: %s' % pofile
continue continue
@@ -89,6 +88,7 @@ for pofile in pofiles:
lang = CODE2LANG[pofile[:-3]] lang = CODE2LANG[pofile[:-3]]
except KeyError: except KeyError:
print 'Language for %s not defined!' % pofile print 'Language for %s not defined!' % pofile
continue
try: try:
langfile = codecs.open('lang/%s-utf-8.inc.php' % lang, 'r', 'utf-8').readlines() langfile = codecs.open('lang/%s-utf-8.inc.php' % lang, 'r', 'utf-8').readlines()
@@ -97,7 +97,7 @@ for pofile in pofiles:
continue continue
print 'Updating %s from: %s' % (lang, pofile) print 'Updating %s from: %s' % (lang, pofile)
po = polib.pofile(os.path.join(sys.argv[1], pofile)) po = polib.pofile(os.path.join(sys.argv[1], pofile_full))
for translation in po.translated_entries(): for translation in po.translated_entries():
if translation.msgctxt is None: if translation.msgctxt is None:
@@ -110,7 +110,7 @@ for pofile in pofiles:
continue continue
for i in xrange(len(langfile)): for i in xrange(len(langfile)):
if langfile[i][:2 + keylen] == '$%s ' % key: if langfile[i][:2 + keylen] == '$%s ' % key:
langfile[i] = '$%s = \'%s\';\n' % (key, msgstr) langfile[i] = u'$%s = \'%s\';\n' % (key, msgstr)
out = file('lang/%s-utf-8.inc.php' % lang, 'w') out = codecs.open('lang/%s-utf-8.inc.php' % lang, 'w', 'utf-8')
out.writelines([x.encode('utf-8') for x in langfile]) out.writelines(langfile)