Skip to content

Instantly share code, notes, and snippets.

@stasm
Created May 20, 2010 23:48
Show Gist options
  • Save stasm/408284 to your computer and use it in GitHub Desktop.
Save stasm/408284 to your computer and use it in GitHub Desktop.
#! /bin/env python
import os
import sys
from subprocess import Popen
from tempfile import TemporaryFile
from translate.tools import phppo2pypo
# How can we access settings.STANDALONE_DOMAINS from here?
standalone_domains = ['firefoxcup']
def copypos(dir):
if not os.path.isdir(dir):
sys.exit("Can't find (%s)" % dir)
os.chdir(dir)
for locale in os.listdir('.'):
if not os.path.isdir(locale) or locale.startswith('.'):
continue
print "Creating z-messages for %s..." % locale
r_messages = open(os.path.join(os.path.abspath(locale), 'LC_MESSAGES',
'messages.po'))
r_messages_python = TemporaryFile('w+t')
if not phppo2pypo.convertphp2py(r_messages, r_messages_python):
sys.exit("Something is broken in (%s)" % r_messages)
r_messages.close()
r_messages_python.seek(0)
standalone_messages = []
for domain in standalone_domains:
standalone_messages.append(os.path.join(os.path.abspath(locale),
'LC_MESSAGES',
'z-%s.po' % domain))
z_messages = open(os.path.join(os.path.abspath(locale), 'LC_MESSAGES',
'z-messages.po'), 'w+t')
command = ["msgcat", "--use-first", "-"]
command.extend(standalone_messages)
p1 = Popen(command, stdin=r_messages_python, stdout=z_messages)
p1.communicate()
z_messages.close()
if __name__ == "__main__":
if len(sys.argv) != 2:
sys.exit("Usage: ./copy-to-zamboni.sh <localedir>")
copypos(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment