<?xml version="1.0" encoding="UTF-8"?>
<project name="PslSearchForm" basedir=".">
    <property name="module.dir" location="."/>
    <property name="omeka.dir" location="../.."/>
    <property name="lang.dir" location="language" />
    <property name="composer.vendor.path" location="${omeka.dir}/vendor"/>
    <property name="composer.bin.path" location="${composer.vendor.path}/bin"/>
    <target name="update-pot" description="Update the translation template.">
        <property name="pot.file" location="${lang.dir}/template.pot"/>
        <property name="pot.base" location="${lang.dir}/template.base.pot"/>
        <tempfile property="pot.temp" suffix=".pot"/>
        <tempfile property="pot.duplicates" suffix="-duplicates.pot" />
        <tempfile property="xgettext.temp" suffix=".pot" destdir="${lang.dir}" createfile="true" deleteonexit="true" />
        <tempfile property="tagged.temp" suffix=".pot" destdir="${lang.dir}" deleteonexit="true"/>
        <copy file="${pot.base}" tofile="${pot.temp}"/>
        <apply executable="xgettext" relative="true" parallel="true" verbose="true">
            <arg value="--language=php"/>
            <arg value="--from-code=utf-8"/>
            <arg value="--keyword=translate"/>
            <arg value="--omit-header"/>
            <arg value="--join-existing"/>
            <arg value="-o"/>
            <arg file="${pot.temp}"/>
            <fileset dir="." includes="**/*.php **/*.phtml"
                excludes="test/"/>
        </apply>
        <exec executable="${composer.bin.path}/extract-tagged-strings.php" dir="${omeka.dir}" output="${tagged.temp}">
            <arg value="${module.dir}"/>
        </exec>
        <exec executable="msgcat">
            <arg file="${pot.temp}"/>
            <arg file="${tagged.temp}"/>
            <arg value="-o"/>
            <arg file="${pot.temp}"/>
        </exec>
        <move file="${pot.temp}" tofile="${pot.file}"/>
        <delete file="${pot.duplicates}" quiet="true" />
    </target>

    <target name="build-mo" description="Build the MO translation files.">
        <apply executable="msgfmt" dest="${lang.dir}" verbose="true">
            <arg value="-o"/>
            <targetfile />
            <srcfile />
            <fileset dir="${lang.dir}" includes="*.po"/>
            <mapper type="glob" from="*.po" to="*.mo"/>
        </apply>
    </target>
</project>
