diff options
Diffstat (limited to 'zarb-ml/mageia-i18n/attachments/20120916/87670d39/attachment-0001.obj')
-rw-r--r-- | zarb-ml/mageia-i18n/attachments/20120916/87670d39/attachment-0001.obj | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/zarb-ml/mageia-i18n/attachments/20120916/87670d39/attachment-0001.obj b/zarb-ml/mageia-i18n/attachments/20120916/87670d39/attachment-0001.obj new file mode 100644 index 000000000..752a2e6d8 --- /dev/null +++ b/zarb-ml/mageia-i18n/attachments/20120916/87670d39/attachment-0001.obj @@ -0,0 +1,73 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import errno, glob, polib, re, os +from time import strftime + +for langfile in glob.glob('*.en.lang'): + langfilename = langfile.replace('.en.lang', '') + # Create localization directories if needed + podir = langfilename + '/po' + try: + os.makedirs(podir) + except OSError, e: + if e.errno != errno.EEXIST: + raise + #open lang file + text = open(langfile,"r").read() + newtext = text.split('\n\n',1)[0] + + # Write POT file + pot = polib.POFile() + potcreationtime = strftime('%Y-%m-%d %H:%M%z') + pot.metadata = { + 'Project-Id-Version': langfile, + 'Report-Msgid-Bugs-To': 'mageia-i18n@mageia.org', + 'POT-Creation-Date': potcreationtime, + 'PO-Revision-Date': 'YEAR-MO-DA HO:MI+ZONE', + 'Last-Translator': 'FULL NAME <EMAIL@ADDRESS>', + 'Language-Team': 'LANGUAGE <LL@li.org>', + 'MIME-Version': '1.0', + 'Content-Type': 'text/plain; charset=CHARSET', + 'Content-Transfer-Encoding': '8bit', + } + + # Parse contents and add them to POT + messagetemplate='\n\n#\ .*?\n\;.*?\n.*?\n' + mpattern=re.compile(messagetemplate,re.DOTALL) + for mblock in mpattern.findall(text): + print mblock + mblock_stripped = mblock.strip('\n') + message_comment, message_text = mblock.strip('\n').split('\n',1) + # Strip '# ' from comments + message_comment = message_comment.lstrip('# ') + message_id, message_str = message_text.split('\n',1) + # Strip ';' from msgid + message_id = message_id.lstrip(';') + potentry = polib.POEntry( + msgctxt = message_comment, + msgid = message_id.decode('utf-8'), + msgstr = '', + occurrences=[(langfile,'')] + ) + pot.append(potentry) + potfilename = langfilename + '/po/' + langfilename + '.pot' + pot.save(potfilename) + + # Parse PO files + for pofile in glob.glob(podir + '/*.po'): + lang = pofile[:-3].rsplit('/',1)[1] + pofilename = pofile + po = polib.pofile(pofilename) + po.merge(pot) + po.save(pofilename) + content = newtext + '\n\n' + for entry in po.translated_entries(): + content = content + ('# ' + entry.msgctxt + '\n;' + entry.msgid + '\n' + entry.msgstr).encode('utf-8') + if entry.msgid == entry.msgstr: + content = content + ' {ok}' + content = content + '\n\n' + translatedlang = open(langfile.rstrip('.en.lang') + '.' + lang + '.lang', "w") + translatedlang.write(content) + translatedlang.close() + |