Import('env')
from os.path import join, basename

languages = []
for src in env.Glob('*.po'):
    lang = basename(str(src))[:-3]
    languages.append(lang)
    dst = join(lang, "LC_MESSAGES", 'mypaint.mo')
    env.Command(dst, src, 'msgfmt $SOURCE -o $TARGET')

lang = ARGUMENTS.get('translate')
if lang:
    env.Execute('git grep --full-name --files-with-matches "^from gettext import" .. | sort > POTFILES.in')
    env.Execute('intltool-update -g mypaint --pot')
    if lang == 'all':
        translate = languages
    elif lang == 'pot':
        translate = []
    else:
        translate = [lang]
    for lang in translate:
        env.Execute('intltool-update -g mypaint %s' % lang)
    # don't build any targets
    Exit()

Return('languages')
