#!/bin/sh

set -eux

branch=$1
dir=$2
target="$(readlink -f "${3}")"

tmpdir="$(mktemp -d)"
cd "${tmpdir}"

cleanup () {
    rm -rf "${tmpdir}"
}

trap cleanup EXIT

mkdir -p $target

git clone $branch checkout
for po in checkout/$dir/*.po; do
    msgfmt "${po}" -o "${target}/$(basename "${po}" .po).mo"
done