#!/bin/sh
set -e

# Copyright 2014 Aurélien Gâteau <mail@agateau.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

old_pwd=$PWD
cd $(dirname $0)
script_dir=$PWD
cd $old_pwd

die() {
    echo "ERROR: $*" >&2
    exit 1
}

usage() {
    echo "$(basename $0) <src-po-dir> <dst-java-dir>"
    exit 1
}

if [ $# != 2 ] ; then
    usage
fi

src="$1"
dst="$2"

if [ ! -d "$src" ] ; then
    die "'$src' is not a dir"
fi

if [ ! -d "$dst" ] ; then
    die "'$dst' is not a dir"
fi

for po in $src/*.po ; do
    echo "Compiling $po"
    locale=$(basename $po .po)
    $script_dir/po-compile -o $dst/Messages_$locale.java -l $locale $po
done
