Skip to content

Commit

Permalink
parallelize locale compilation (#21889)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMind committed Feb 21, 2024
1 parent 72a2f69 commit e374a72
Showing 1 changed file with 16 additions and 30 deletions.
46 changes: 16 additions & 30 deletions locale/compile-mo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@
# Make this script fail if any command exits wit exit code != 0
set -e

function process_po_file() {
pofile=$1
dir=$(dirname "$pofile")
lang=$(echo "$pofile" | cut -d "/" -f2)
stem=$(basename "$pofile" .po)
touch "${dir}/${stem}.mo"
dennis-cmd lint --errorsonly "$pofile" && msgfmt -o "${dir}/${stem}.mo" "$pofile"
}

# We are spawning sub processes with `xargs`
# and the function needs to be available in that sub process
export -f process_po_file

function usage() {
echo "syntax:"
echo "compile-mo.sh locale-dir/"
Expand All @@ -17,34 +30,7 @@ if [[ ($# -ne 1) || (! -d "$1") ]]; then usage; fi
hash dennis-cmd 2>/dev/null || source $VENV/bin/activate

echo "compiling django.po..."
for pofile in `find $1 -type f -name "django.po"`; do
dir=`dirname $pofile`
lang=`echo $pofile | cut -d "/" -f2`
stem=`basename $pofile .po`
# lint the .po file
dennis-cmd lint --errorsonly "$pofile"

if [ $? -ne 0 ]
then
exit 1
else
msgfmt -o ${dir}/${stem}.mo $pofile
fi
done

echo
find $1 -type f -name "django.po" -print0 | xargs -0 -n1 -P4 bash -c 'process_po_file "$@"' _

echo "compiling djangojs.po..."
for pofile in `find $1 -type f -name "djangojs.po"`; do
dir=`dirname $pofile`
lang=`echo $pofile | cut -d "/" -f2`
stem=`basename $pofile .po`
touch "${dir}/${stem}.mo"
# lint the .po file
dennis-cmd lint --errorsonly "$pofile"
if [ $? -ne 0 ]
then
exit 1
else
msgfmt -o ${dir}/${stem}.mo $pofile
fi
done
find $1 -type f -name "djangojs.po" -print0 | xargs -0 -n1 -P4 bash -c 'process_po_file "$@"' _

0 comments on commit e374a72

Please sign in to comment.