aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2022-01-18 11:39:07 -0300
committerEuAndreh <eu@euandre.org>2022-01-18 11:39:07 -0300
commit89a8519526acc045ea90fcb2e5c0e3ff7f3761e0 (patch)
treed36e65ff8e7d3ab3ccb18b59d697d4977de007b9
parentTODOs.md: Add #td-06b21a7e-ccea-55ea-4136-96e27a92f25a (diff)
downloadgit-permalink-89a8519526acc045ea90fcb2e5c0e3ff7f3761e0.tar.gz
git-permalink-89a8519526acc045ea90fcb2e5c0e3ff7f3761e0.tar.xz
aux/workflow/l10n.sh: Generate and consume pofiles in parallel
-rwxr-xr-xaux/workflow/l10n.sh97
1 files changed, 63 insertions, 34 deletions
diff --git a/aux/workflow/l10n.sh b/aux/workflow/l10n.sh
index d3dc9df..cb132a3 100755
--- a/aux/workflow/l10n.sh
+++ b/aux/workflow/l10n.sh
@@ -2,7 +2,8 @@
set -eu
LANGS=
-while getopts 'l:L:' flag; do
+MAX_JOBS=64
+while getopts 'l:L:j:' flag; do
case "$flag" in
l)
LANGS="$OPTARG"
@@ -10,6 +11,9 @@ while getopts 'l:L:' flag; do
L)
CONTRIBLANGS="$OPTARG"
;;
+ j)
+ MAX_JOBS="$OPTARG"
+ ;;
*)
exit 2
;;
@@ -26,44 +30,64 @@ assert_arg() {
assert_arg "${LANGS:-}" '-l LANGS'
+PARALLEL_N=0
+parallel_run() {
+ {
+ "$@"
+ } &
+ PARALLEL_N=$((PARALLEL_N + 1))
+ if [ "$PARALLEL_N" = "$MAX_JOBS" ]; then
+ wait
+ PARALLEL_N=0
+ fi
+}
+
+po_run() {
+ from_f="$1"
+ lang="$2"
+ to_f="$(echo "$from_f" | sed "s/en\./$lang./")"
+ printf 'Generating %s...\n' "$to_f" >&2
+ pofile="po/LC_MESSAGES/$from_f/$lang.po"
+ mkdir -p "$(dirname "$pofile")"
+
+ case "$from_f" in
+ *.en.[1-9].in)
+ po4a-updatepo -f man -m "$from_f" -p "$pofile"
+ po4a-translate -f man -m "$from_f" \
+ -p "$pofile" -l "$to_f" -k 0 -v >&2
+ ;;
+ *.en.html)
+ po4a-updatepo -f xhtml -m "$from_f" -p "$pofile"
+ po4a-translate -f xhtml -m "$from_f" \
+ -p "$pofile" -l "$to_f" -k 0 -v >&2
+ ;;
+ *.en.md)
+ touch "$pofile"
+ md2po --include-codeblocks --quiet --save \
+ --po-filepath "$pofile" < "$from_f"
+ po2md --pofiles "$pofile" --save "$to_f" \
+ --quiet --wrapwidth 999 < "$from_f"
+ ;;
+ *.en.msg|*.en.txt)
+ po4a-updatepo -f text -m "$from_f" -p "$pofile"
+ po4a-translate -f text -m "$from_f" \
+ -p "$pofile" -l "$to_f" -k 0 -v >&2
+ ;;
+ *)
+ echo "Unsupported file format: $from_f" >&2
+ exit 2
+ ;;
+ esac
+}
+
for from_f in "$@"; do
for lang in $LANGS ${CONTRIBLANGS:-}; do
- to_f="$(echo "$from_f" | sed "s/en\./$lang./")"
- printf 'Generating %s...\n' "$to_f" >&2
- pofile="po/LC_MESSAGES/$from_f/$lang.po"
- mkdir -p "$(dirname "$pofile")"
-
- case "$from_f" in
- *.en.[1-9].in)
- po4a-updatepo -f man -m "$from_f" -p "$pofile"
- po4a-translate -f man -m "$from_f" \
- -p "$pofile" -l "$to_f" -k 0 -v >&2
- ;;
- *.en.html)
- po4a-updatepo -f xhtml -m "$from_f" -p "$pofile"
- po4a-translate -f xhtml -m "$from_f" \
- -p "$pofile" -l "$to_f" -k 0 -v >&2
- ;;
- *.en.md)
- touch "$pofile"
- md2po --include-codeblocks --quiet --save \
- --po-filepath "$pofile" < "$from_f"
- po2md --pofiles "$pofile" --save "$to_f" \
- --quiet --wrapwidth 999 < "$from_f"
- ;;
- *.en.msg|*.en.txt)
- po4a-updatepo -f text -m "$from_f" -p "$pofile"
- po4a-translate -f text -m "$from_f" \
- -p "$pofile" -l "$to_f" -k 0 -v >&2
- ;;
- *)
- echo "Unsupported file format: $from_f" >&2
- exit 2
- ;;
- esac
+ parallel_run po_run "$from_f" "$lang"
done
done
+EXIT_CODE=0
+
end="\033[0m"
yellowb="\033[1;33m"
for lang in $LANGS; do
@@ -76,5 +100,10 @@ for lang in $LANGS; do
# shellcheck disable=2059
printf "\n ${yellowb}WARNING${end}!" >&2
printf "\n Missing translations for %s\n\n" "$pofile" >&2
+ EXIT_CODE=1
done
done
+
+if [ -n "${ASSERT_NO_MISSING_TRANSLATIONS:-}" ]; then
+ exit "$EXIT_CODE"
+fi