Improve bin/run_xgettext script

- Exclude more folders from find
- Add progress ratio
- Add computed current year
This commit is contained in:
Hypolite Petovan 2020-04-05 11:11:59 -04:00
parent cc1bf3edf9
commit 4621da7ef2

View file

@ -32,7 +32,7 @@ case "$MODE" in
mkdir -p "$FULLPATH/../addon/$ADDONNAME/lang/C" mkdir -p "$FULLPATH/../addon/$ADDONNAME/lang/C"
OUTFILE="$FULLPATH/../addon/$ADDONNAME/lang/C/messages.po" OUTFILE="$FULLPATH/../addon/$ADDONNAME/lang/C/messages.po"
FINDSTARTDIR="." FINDSTARTDIR="."
FINDOPTS= FINDOPTS="-path ./vendor -prune -or"
;; ;;
'single') 'single')
FULLPATH=$PWD FULLPATH=$PWD
@ -40,7 +40,7 @@ case "$MODE" in
mkdir -p "$FULLPATH/lang/C" mkdir -p "$FULLPATH/lang/C"
OUTFILE="$FULLPATH/lang/C/messages.po" OUTFILE="$FULLPATH/lang/C/messages.po"
FINDSTARTDIR="." FINDSTARTDIR="."
FINDOPTS= FINDOPTS="-path ./vendor -prune -or"
echo "Extract strings for single addon '$ADDONNAME'" echo "Extract strings for single addon '$ADDONNAME'"
;; ;;
'default') 'default')
@ -48,7 +48,7 @@ case "$MODE" in
OUTFILE="$FULLPATH/../view/lang/C/messages.po" OUTFILE="$FULLPATH/../view/lang/C/messages.po"
FINDSTARTDIR="." FINDSTARTDIR="."
# skip addon folder # skip addon folder
FINDOPTS="( -wholename */addon -or -wholename */addons -or -wholename */addons-extra -or -wholename */smarty3 ) -prune -o" FINDOPTS="( -path ./addon -or -path ./addons -or -path ./addons-extra -or -path ./tests -or -path ./view/lang -or -path ./view/smarty3 -or -path ./vendor ) -prune -or"
F9KVERSION=$(cat ./VERSION); F9KVERSION=$(cat ./VERSION);
echo "Friendica version $F9KVERSION" echo "Friendica version $F9KVERSION"
@ -58,18 +58,32 @@ esac
KEYWORDS="-k -kt -ktt:1,2" KEYWORDS="-k -kt -ktt:1,2"
echo "extract strings to $OUTFILE.." echo "Extract strings to $OUTFILE.."
rm "$OUTFILE"; touch "$OUTFILE" rm "$OUTFILE"; touch "$OUTFILE"
for f in $(find "$FINDSTARTDIR" $FINDOPTS -name "*.php" -type f)
find_result=$(find "$FINDSTARTDIR" $FINDOPTS -name "*.php" -type f)
total_files=$(wc -l <<< "${find_result}")
for file in $find_result
do do
if [ ! -d "$f" ] ((count++))
echo -ne " \r"
echo -ne "Reading file $count/$total_files..."
# On Windows, find still outputs the name of pruned folders
if [ ! -d "$file" ]
then then
xgettext $KEYWORDS -j -o "$OUTFILE" --from-code=UTF-8 "$f" xgettext $KEYWORDS -j -o "$OUTFILE" --from-code=UTF-8 "$file" || exit 1
sed -i "s/CHARSET/UTF-8/g" "$OUTFILE" sed -i "s/CHARSET/UTF-8/g" "$OUTFILE"
fi fi
done done
echo -ne "\n"
echo "Interpolate metadata.."
sed -i "s/^\"Plural-Forms.*$//g" "$OUTFILE"
echo "setup base info.."
case "$MODE" in case "$MODE" in
'addon'|'single') 'addon'|'single')
sed -i "s/SOME DESCRIPTIVE TITLE./ADDON $ADDONNAME/g" "$OUTFILE" sed -i "s/SOME DESCRIPTIVE TITLE./ADDON $ADDONNAME/g" "$OUTFILE"
@ -77,25 +91,21 @@ case "$MODE" in
sed -i "s/FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.//g" "$OUTFILE" sed -i "s/FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.//g" "$OUTFILE"
sed -i "s/PACKAGE VERSION//g" "$OUTFILE" sed -i "s/PACKAGE VERSION//g" "$OUTFILE"
sed -i "s/PACKAGE/Friendica $ADDONNAME addon/g" "$OUTFILE" sed -i "s/PACKAGE/Friendica $ADDONNAME addon/g" "$OUTFILE"
sed -i "s/CHARSET/UTF-8/g" "$OUTFILE"
sed -i "s/^\"Plural-Forms.*$//g" "$OUTFILE"
;; ;;
'default') 'default')
sed -i "s/SOME DESCRIPTIVE TITLE./FRIENDICA Distributed Social Network/g" "$OUTFILE" sed -i "s/SOME DESCRIPTIVE TITLE./FRIENDICA Distributed Social Network/g" "$OUTFILE"
sed -i "s/YEAR THE PACKAGE'S COPYRIGHT HOLDER/2010, 2011, 2012, 2013 the Friendica Project/g" "$OUTFILE" sed -i "s/YEAR THE PACKAGE'S COPYRIGHT HOLDER/2010-$(date +%Y) the Friendica Project/g" "$OUTFILE"
sed -i "s/FIRST AUTHOR <EMAIL@ADDRESS>, YEAR./Mike Macgirvin, 2010/g" "$OUTFILE" sed -i "s/FIRST AUTHOR <EMAIL@ADDRESS>, YEAR./Mike Macgirvin, 2010/g" "$OUTFILE"
sed -i "s/PACKAGE VERSION/$F9KVERSION/g" "$OUTFILE" sed -i "s/PACKAGE VERSION/$F9KVERSION/g" "$OUTFILE"
sed -i "s/PACKAGE/Friendica/g" "$OUTFILE" sed -i "s/PACKAGE/Friendica/g" "$OUTFILE"
sed -i "s/CHARSET/UTF-8/g" "$OUTFILE"
sed -i "s/^\"Plural-Forms.*$//g" "$OUTFILE"
;; ;;
esac esac
if [ "" != "$1" -a "$MODE" == "default" ] if [ "" != "$1" -a "$MODE" == "default" ]
then then
UPDATEFILE="$(readlink -f ${FULLPATH}/$1)" UPDATEFILE="$(readlink -f ${FULLPATH}/$1)"
echo "merging new strings to $UPDATEFILE.." echo "Merging new strings to $UPDATEFILE.."
msgmerge -U $OUTFILE $UPDATEFILE msgmerge -U $OUTFILE $UPDATEFILE
fi fi
echo "done." echo "Done."