#!/bin/sh

LOCALES='ru'

echo "Locales: ${LOCALES}"

export QT_SELECT=5

for tr_dir in `find ../ -type d -name "translations"`
do

     plug_name=`echo $tr_dir | rev | cut -d "/" -f 2 | rev`

     case $plug_name in
        app)
            plug_name="fly-ocr"
        ;;
     esac

     echo "Updating ${plug_name}"

     ts_files=''
     qm_files=''

     if [ "$plug_name" = "fly-ocr" ]; then
        for code in $LOCALES
        do
      	    ts_files="${ts_files} ${tr_dir}/${plug_name}_${code}.ts"
            if [ "${code}" != "en" ]; then
              qm_files="${qm_files} ${plug_name}_${code}.qm"
            fi
      	done
        qrc_file="${tr_dir}/${plug_name}_locales.qrc"
     else
        for code in $LOCALES
        do
      	    ts_files="${ts_files} ${tr_dir}/${plug_name}_plugin_${code}.ts"
            if [ "${code}" != "en" ]; then
              qm_files="${qm_files} ${plug_name}_plugin_${code}.qm"
            fi
      	done
        qrc_file="${tr_dir}/translations.qrc"
     fi

     lupdate -no-obsolete -silent -extensions "cpp,ui,h" ${tr_dir}/../ -ts ${ts_files}


     echo "<!DOCTYPE RCC>" > $qrc_file
     echo "<RCC version=\"1.0\">" >> $qrc_file
     echo "  <qresource>" >> $qrc_file
     for qm_file in $qm_files
     do
         echo "    <file>${qm_file}</file>" >> $qrc_file;
     done
     echo "  </qresource>" >> $qrc_file
     echo "</RCC>" >> $qrc_file
done
