#!/bin/sh
# Copyright (C) 2016-2018 Greenbone Networks GmbH
#
# SPDX-License-Identifier: GPL-2.0-or-later
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.

# Utility to generate a pot file from gsa JavaScript i18n

if [ $# -lt 3 ]; then
  echo "Missing required parameters" > 2;
  exit 1;
fi

SOURCE_BASEDIR=$1
POT_FILE=$2
SOURCE_DIR=$3

mkdir -p `dirname $POT_FILE`

cd "$SOURCE_BASEDIR" || exit 2
SOURCES_ABS=`find -L $SOURCE_DIR -name "*.js" -not -path "*/node_modules/*" -not -path "*/build/*" -not -path "*/__tests__/*"`

SOURCES=""
for SOURCE_FILE in $SOURCES_ABS
do
  REL_FILE=$(realpath --relative-to "$SOURCE_BASEDIR" "$SOURCE_FILE")
  echo "$REL_FILE"
  SOURCES="${SOURCES}${REL_FILE}
"
done

xgettext --from-code=UTF-8 --keyword=_l -o "$POT_FILE" -L JavaScript $SOURCES
