build: i18n-sync script refinements
authorPaul Donald <newtwen@gmail.com>
Tue, 13 Feb 2024 03:11:41 +0000 (04:11 +0100)
committerPaul Donald <newtwen@gmail.com>
Tue, 13 Feb 2024 04:34:29 +0000 (05:34 +0100)
add -P x to xargs for x number of processes.

Signed-off-by: Paul Donald <newtwen@gmail.com>
build/i18n-sync.sh

index 9a3060a42d9342938b4f511cae475083432c1431..6d36ca4f0dd214f9d17879f5ffdae66b9b7bca8e 100755 (executable)
@@ -1,24 +1,65 @@
 #!/bin/sh
 
-[ -d ./build ] || {
+print_help() { 
        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
 }
 
+case $1 in
+       -h | --help )
+               print_help
+               exit 0
+               ;;
+esac
+
+[ -n "$1" ] && set -- "${1%/}"
+
 [ -n "$1" ] || ./build/mkbasepot.sh
 
-find "${1:-.}" -name '*.pot' -and -not -name base.pot | \
-       while read path; do
-               dir="${path%/po/templates/*}"
-               echo -n "Updating ${path#./} ... "
-               ./build/i18n-scan.pl "$dir" > "$path"
-               echo "done"
-       done
+# Absent a [folder] parameter, use the current path
+find "${1:-.}" -name '*.pot' -and -not -name base.pot | sort | \
+    xargs -P 10 -I{} sh -c '
+        dir="${1%/po/templates/*}"
+        echo "Updating ${1#./} ... "
+        ./build/i18n-scan.pl "$dir" > "$1"
+        echo "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
-       find "$1" -path '*/templates/*.pot' -printf '%h ' | \
-               xargs -r -n 1 dirname | \
-               xargs -r -n 1 ./build/i18n-update.pl
+       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 ' | \
+                       xargs -r -n 1 dirname | \
+                       xargs -r -n 1 -P 40 ./build/i18n-update.pl
+       # elif [ "$(uname)" = "SunOS" ]; then
+       #       # Solaris-specific commands
+       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
 fi