#!/usr/bin/env bash

APPNAME="$(basename $(dirname $(pwd)))"

echodo() {
  echo "${@}"
  ${@}
}

# Prepare transifex
if [ ! -s  .tx/config ]; then
   mkdir -p .tx
   cat <<EOF > .tx/config
[main]
host = https://www.transifex.com

[o:anticapitalista:p:antix-development:r:$APPNAME]
file_filter = ./${APPNAME}_<lang>.ts
source_file = ${APPNAME}_en.ts
source_lang = en
type        = ts
minimum_perc = 25
EOF
fi    

# Migrate percent checking
if [ -z "$(grep minimum_perc .tx/config)" ]; then
        echo "minimum_perc = 25" >> .tx/config
fi

# Remove existing translations
find . -type f -name '*.ts' -not -name '*en.ts' -delete

# Get all translations
if command -v tx >/dev/null; then
   echodo tx pull -r antix-development.$APPNAME --all
fi

lupdate ../*.pro # Update en.ts file
lupdate ../*.cpp ../*.h ../*.ui -ts *.ts
