Skip to content

Instantly share code, notes, and snippets.

@mpj
Created October 7, 2010 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpj/615555 to your computer and use it in GitHub Desktop.
Save mpj/615555 to your computer and use it in GitHub Desktop.
import sys, os, traceback, optparse
import polib
from xml.dom.minidom import Document
import time
import re
#from pexpect import run, spawn
def main ():
doc = Document()
i18n = doc.createElement("i18n")
doc.appendChild(i18n)
# load an existing po file
po = polib.pofile('russian.po')
for entry in po:
translation = doc.createElement("translation")
i18n.appendChild(translation)
key = doc.createElement("key")
translation.appendChild(key)
value = doc.createElement("value")
translation.appendChild(value)
key_text = doc.createTextNode(entry.msgctxt)
key.appendChild(key_text)
value_text = doc.createTextNode(entry.msgstr)
value.appendChild(value_text)
# Print our newly created XML
pretty_xml = doc.toprettyxml().encode('UTF-8')
handle = open("ru-pytte.xml", "wb")
handle.write(pretty_xml)
handle.close()
print "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment