#!/usr/bin/env bash

set -e

if [[ "$OSTYPE" == "darwin14" ]]; then
  tmpdir=/tmp/i18n-checkup-$(uuidgen)
  mkdir -p ${tmpdir}
else
  tmpdir=$(mktemp -d)
fi

function cleanup {
  rm -rf ${tmpdir}
}
trap cleanup EXIT

echo -e "\n Updating i18n4go..."
go get -u github.com/XenoPhex/i18n4go/i18n4go
if [ $? -ne 0 ]; then
  printf "Failed to run `go get -u github.com/XenoPhex/i18n4go/i18n4go`"
  exit 1
fi


IGNORE_FILES_REGEX=".*test.go|.*resources.go|fake.*\.go|template.go"

i18n4go -c extract-strings -e strings/excluded.json -s strings/specialStrings.json -o ${tmpdir} -d command -r --ignore-regexp $IGNORE_FILES_REGEX
i18n4go -c extract-strings -e strings/excluded.json -s strings/specialStrings.json -o ${tmpdir} -d cf -r --ignore-regexp $IGNORE_FILES_REGEX
i18n4go -c merge-strings -d ${tmpdir}

i18n4go -c create-translations -f ${tmpdir}/en.all.json -languages "de-de,en-us,es-es,fr-fr,it-it,ja-jp,ko-kr,pt-br,zh-hans,zh-hant"

go run bin/reformat_translated_json.go ./
