Skip to content

Commit

Permalink
xml/po converter: .po to .xml conversion with msgctxt as tag
Browse files Browse the repository at this point in the history
  • Loading branch information
scrawl committed Apr 11, 2011
1 parent a8ba61e commit bddb0fd
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions locale/xml_po_parser.py
Expand Up @@ -74,22 +74,30 @@ def usage():
# read po
for line in f1:
if line.strip().startswith("\""):
if last == "msgid":
if last == "msgctxt":
msgid += line.strip().split("\"")[1].replace("\\n", "\n")
elif last == "msgstr":
msgstr += line.strip().split("\"")[1].replace("\\n", "\n")
if line.strip().startswith("msgid"):
if line.strip().startswith("msgctxt"):
# add previous msgstr
if msgid != "":
msgs[msgid] = msgstr

msgid = line.split("\"")[1].replace("\\n", "\n")
last = "msgid"
last = "msgctxt"
if line.strip().startswith("msgstr"):
msgstr =line.split("\"")[1].replace("\\n", "\n")
last = "msgstr"

# write xml
result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
<MyGUI>\n"

print msgs
for mid, mstr in msgs.items():
result += "\t<Tag name=\"" + mid + "\">" + mstr + "</Tag>\n"

result += "\n</MyGUI>"
f2.write(result)

else:
usage()
Expand Down

0 comments on commit bddb0fd

Please sign in to comment.