#!/bin/bash

# Exports all translations to a bazaar branch to be used by Launchpad

# Dependencies: translate-toolkit, gettext, tofrodos, native2ascii, bzr

# trap and exit on error
set -e
trap "echo Export failed." ERR

# usage
if [ $# != 0 -o "$1" = "-h" -o "$1" = "--help" ]; then
    echo "Usage: $0"
    echo "Example: $0"
    exit 1
fi

# go to the program directory
cd "`dirname "$0"`"

PODIR="$PWD/../po"
BZRDIR="$PWD/../../translations/export"

# update translations
./update-translations

# copy translations
cd "$PODIR"
echo "Copying files..."
cp esmska.pot "$BZRDIR"

# remove value from translator-credits because of Launchpad bug #278955
for PO in *.po; do
    sed '/#\. #Provide names and contacts to translators/,/^$/d' "$PO" > "$BZRDIR/$PO"
done

# commit changes
cd "$BZRDIR"
echo "Commiting changes..."
bzr add .
bzr commit -m "translation update"

