From 014f0f4bdf001e1e5e02a3ad307b803d7c97ac9c Mon Sep 17 00:00:00 2001 From: Andrey Petelin Date: Tue, 30 Sep 2025 13:04:44 +0500 Subject: [PATCH] feat: Add scripts for generating and updating translation templates --- luci-app-podkop/msgmerge.sh | 29 +++++++++++++++++++++++++++++ luci-app-podkop/xgettext.sh | 22 ++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 luci-app-podkop/msgmerge.sh create mode 100644 luci-app-podkop/xgettext.sh diff --git a/luci-app-podkop/msgmerge.sh b/luci-app-podkop/msgmerge.sh new file mode 100644 index 0000000..7e0c9dd --- /dev/null +++ b/luci-app-podkop/msgmerge.sh @@ -0,0 +1,29 @@ +#!/bin/bash +set -euo pipefail + +PODIR="po" +POTFILE="$PODIR/templates/podkop.pot" + +if [ $# -ne 1 ]; then + echo "Usage: $0 (e.g., ru, de, fr)" + exit 1 +fi + +LANG="$1" +POFILE="$PODIR/$LANG/podkop.po" + +if [ ! -f "$POTFILE" ]; then + echo "Template $POTFILE not found. Run xgettext first." + exit 1 +fi + +if [ -f "$POFILE" ]; then + echo "Updating $POFILE" + msgmerge --update "$POFILE" "$POTFILE" +else + echo "Creating new $POFILE using msginit" + mkdir -p "$PODIR/$LANG" + msginit --no-translator --locale="$LANG" --input="$POTFILE" --output-file="$POFILE" +fi + +echo "Translation file for $LANG updated." \ No newline at end of file diff --git a/luci-app-podkop/xgettext.sh b/luci-app-podkop/xgettext.sh new file mode 100644 index 0000000..a981da7 --- /dev/null +++ b/luci-app-podkop/xgettext.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +SRC_DIR="htdocs/luci-static/resources/view/podkop" +OUT_POT="po/templates/podkop.pot" +ENCODING="UTF-8" + +mapfile -t FILES < <(find "$SRC_DIR" -type f -name "*.js") +if [ ${#FILES[@]} -eq 0 ]; then + echo "No JS files found in $SRC_DIR" + exit 1 +fi + +mkdir -p "$(dirname "$OUT_POT")" + +echo "Generating POT template from JS files in $SRC_DIR" +xgettext --language=JavaScript \ + --keyword=_ \ + --from-code="$ENCODING" \ + --output="$OUT_POT" \ + "${FILES[@]}" + +echo "POT template generated: $OUT_POT" \ No newline at end of file