13
'be': 'belarusian_cyrillic',
14
'be@latin': 'belarusian_latin',
23
'en_GB': 'english-gb',
42
'mk': 'macedonian_cyrillic',
48
'pt_BR': 'brazilian_portuguese',
56
'sr@latin': 'serbian_latin',
57
'sr': 'serbian_cyrillic',
63
'zh_TW': 'chinese_traditional',
64
'zh_CN': 'chinese_simplified',
65
'uz': 'uzbek_cyrillic',
66
'uz@latin': 'uzbek_latin',
70
print 'Usage: update-from-po PO_FILES'
73
f = file('lang/english-utf-8.inc.php', 'r')
77
if line[:4] == '$str':
78
parts = line.split(' = ')
79
langmap[parts[1].strip(';').strip('\'')] = parts[0].strip('$')
81
for pofile_full in sys.argv[1:]:
82
pofile = os.path.basename(pofile_full)
83
if pofile[-3:] != '.po':
84
print 'Not a po file, skipping: %s' % pofile
88
lang = CODE2LANG[pofile[:-3]]
90
print 'Language for %s not defined!' % pofile
94
langfile = codecs.open('lang/%s-utf-8.inc.php' % lang, 'r', 'utf-8').readlines()
96
print 'Language file %s does not exist!' % lang
99
print 'Updating %s from: %s' % (lang, pofile)
100
po = polib.pofile(os.path.join(sys.argv[1], pofile_full))
102
for translation in po.translated_entries():
103
if translation.msgctxt is None:
104
msgid = translation.msgid.replace('\'', '\\\'')
105
msgstr = translation.msgstr.replace('\'', '\\\'')
111
for i in xrange(len(langfile)):
112
if langfile[i][:2 + keylen] == '$%s ' % key:
113
langfile[i] = u'$%s = \'%s\';\n' % (key, msgstr)
115
out = codecs.open('lang/%s-utf-8.inc.php' % lang, 'w', 'utf-8')
116
out.writelines(langfile)