#!/bin/sh

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

find "$SCRIPT_DIR/../" -name "*.po" -exec sh -c 'msgfmt "$1" -o "${1%.po}.mo"' _ {} \;

MO_DIR=$( realpath "$SCRIPT_DIR/.." )
DEST_LANG_DIR=$( realpath "$SCRIPT_DIR/../../misc/common/langs" )

for f in $MO_DIR/*.mo ; do
    filename=$( basename -- "$f" )
    lang=${filename:7:2}
    echo "Moving $f to $DEST_LANG_DIR/$lang"
    mv "$f" "$DEST_LANG_DIR/$lang/"
done
