build: i18n-sync script refinements

add -P x to xargs for x number of processes.

Signed-off-by: Paul Donald <newtwen@gmail.com>
This commit is contained in:
Paul Donald 2024-02-13 04:11:41 +01:00
parent eb40b0bd57
commit e88294d7ac

View file

@ -1,24 +1,65 @@
#!/bin/sh #!/bin/sh
[ -d ./build ] || { print_help() {
echo "Execute as ./build/i18n-sync.sh" >&2 echo "Execute as ./build/i18n-sync.sh" >&2
echo "Or run as: ./build/i18n-sync.sh [module folder e.g. applications/luci-app-example]" >&2
}
[ -d ./build ] || {
print_help
exit 1 exit 1
} }
case $1 in
-h | --help )
print_help
exit 0
;;
esac
[ -n "$1" ] && set -- "${1%/}"
[ -n "$1" ] || ./build/mkbasepot.sh [ -n "$1" ] || ./build/mkbasepot.sh
find "${1:-.}" -name '*.pot' -and -not -name base.pot | \ # Absent a [folder] parameter, use the current path
while read path; do find "${1:-.}" -name '*.pot' -and -not -name base.pot | sort | \
dir="${path%/po/templates/*}" xargs -P 10 -I{} sh -c '
echo -n "Updating ${path#./} ... " dir="${1%/po/templates/*}"
./build/i18n-scan.pl "$dir" > "$path" echo "Updating ${1#./} ... "
./build/i18n-scan.pl "$dir" > "$1"
echo "done" echo "done"
done ' sh {}
# while read path; do
# dir="${path%/po/templates/*}"
# echo "Updating ${path#./} ... "
# # Scan for strings in a directory and stash them in the .pot file:
# ./build/i18n-scan.pl "$dir" > "$path"
# echo "done"
# done
if [ -n "$1" ]; then if [ -n "$1" ]; then
if [ "$(uname)" = "Darwin" ] || [ "$(uname)" = "FreeBSD" ]; then
# macOS-specific commands
find "$1" -path '*/templates/*.pot' -print0 | xargs -0r stat -f '%N' | \
xargs -r -n 1 dirname | \
xargs -r -n 1 dirname | sort | \
xargs -r -n 1 -P 40 ./build/i18n-update.pl
elif [ "$(uname)" = "Linux" ]; then
# Linux-specific commands
find "$1" -path '*/templates/*.pot' -printf '%h ' | \ find "$1" -path '*/templates/*.pot' -printf '%h ' | \
xargs -r -n 1 dirname | \ xargs -r -n 1 dirname | \
xargs -r -n 1 ./build/i18n-update.pl xargs -r -n 1 -P 40 ./build/i18n-update.pl
# elif [ "$(uname)" = "SunOS" ]; then
# # Solaris-specific commands
else else
# GNU specific commands can go here:
find "$1" -path '*/templates/*.pot' -printf '%h ' | \
xargs -r -n 1 dirname | \
xargs -r -n 1 -P 40 ./build/i18n-update.pl
fi
else
# this performs operations on all .po files
./build/i18n-update.pl ./build/i18n-update.pl
fi fi