#!/bin/sh
# This file is in the public domain.
# It extracts translateable strings from the JSON file(s).
#
# The resulting 'extracted.h' file is only used by
# gettext, and not in the actual code. We still make
# sure it is legal C code.

BASEDIR=$(dirname $0)

if [ -z $1 ]; then
  TGTDIR=$BASEDIR
else
  TGTDIR=$1
fi

for n in ${BASEDIR}/redux.??.json
do
    jq '.required_attributes[].label' < $n | awk '{print "_(" $0 "),"}' >> ${TGTDIR}/prep.h
done

jq '.countries[].continent' < ${BASEDIR}/redux.countries.json | awk '{print "_(" $0 "),"}' >> ${TGTDIR}/prep.h

jq '.countries[].name' < ${BASEDIR}/redux.countries.json | awk '{print "_(" $0 "),"}' >> ${TGTDIR}/prep.h

echo "// This is a generated file, see extract.sh" > ${TGTDIR}/extracted.h
echo "const char * i18n[] = {" >> ${TGTDIR}/extracted.h
sort ${TGTDIR}/prep.h | uniq >> ${TGTDIR}/extracted.h
echo "};" >> ${TGTDIR}/extracted.h

rm -f ${TGTDIR}/prep.h
