#!/bin/bash

cd "`dirname "$0"`"

clean() {
    subdirs=`cat 'subdirs'`
    for lang in $subdirs; do
        rm -rf "$lang" 2>/dev/null
    done
    rm 'subdirs'
}

get() {
    echo -e "\e[1;31m> svn update $@\e[0m"
    svn update --force "$@"
}

clean

echo -e "\e[1;31m> svn checkout 'svn://anonsvn.kde.org/home/kde/branches/stable/l10n-kde4/' . --depth empty\e[0m"
svn checkout 'svn://anonsvn.kde.org/home/kde/branches/stable/l10n-kde4/' . --depth empty

echo -e "\e[1;31m> svn revert -R .\e[0m"
svn revert -R .

get 'subdirs'

subdirs=`cat 'subdirs' | sed -e '/x-test/d'`
rm 'subdirs'

for lang in $subdirs; do
    echo "=> $lang"
    get --parents "$lang/messages/calligra/krita.po@"
    if test -f "$lang/messages/calligra/krita.po"; then
        echo "$lang" >> 'subdirs'
    else
        rm -rf "$lang"
        continue
    fi
    
    for fil in calligra_shape_vector.po \
               calligra_shape_text.po \
               calligra_shape_paths.po \
               calligra_shape_artistictext.po \
               calligra.po \
               calligra-dockers.po \
               calligra-defaulttools.po \
               KarbonTools.po \
               karbon.po; do
        get --parents "$lang/messages/calligra/$fil@"
    done
    get --parents "$lang/data/calligra/autocorrect/$lang.xml@"
done

get --parents 'scripts'
