#!/usr/bin/env python

import os;
import re;
import subprocess;

outfile = 'po/steadyflow.pot'
pattern = re.compile('^([a-zA-Z_]+)\.po$')

files = subprocess.Popen(['find', 'Steadyflow', 'Steadyflow.Core', 'Steadyflow.UI', '-name', '*.vala'],
	stdout = subprocess.PIPE).communicate()[0].splitlines()

common_args = ['-o', outfile, '--copyright-holder=Maia Kozheva <sikon@ubuntu.com>', '--package-name=steadyflow',
	'--package-version=0.1', '--msgid-bugs-address=sikon@ubuntu.com']

print 'Updating translation template'
subprocess.call(['xgettext', '--from-code=utf-8', '--language=C#', '--keyword=_',
    '--keyword=ngettext:1,2', '--add-comments=///'] + common_args + files)
subprocess.call(['xgettext', '-j', '--language=Glade', '-D', 'data/ui'] + common_args + os.listdir('data/ui'))

for langfile in sorted(os.listdir('po')):
	matches = pattern.match(langfile)
	
	if matches:
		lang = matches.group(1)
		print 'Updating translation file for language "%s"' % lang
		langfile = 'po/%s' % langfile
		subprocess.call(['msgcat', '--use-first', '-o', langfile, langfile, outfile])
