From 1ed0bfbe421affea771948b4226911580d645934 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Thu, 6 Jul 2023 16:01:36 -0300 Subject: v2: mv aux/po4a-cfg.sh src/bin/dyn-po4a --- v2/src/bin/dyn-po4a | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100755 v2/src/bin/dyn-po4a (limited to 'v2/src/bin/dyn-po4a') diff --git a/v2/src/bin/dyn-po4a b/v2/src/bin/dyn-po4a new file mode 100755 index 0000000..9dde6d1 --- /dev/null +++ b/v2/src/bin/dyn-po4a @@ -0,0 +1,113 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + dyn-po4a > po/po4a.cfg + dyn-po4a -h + EOF +} + +help() { + cat <<-'EOF' + + + Options: + -h, --help show this message + + + Discover translatable files in the repository (via + git-ls-files(1)) that have '.en.' or '/en/' in their name and + emit the configuration file to be used with po4a(1). + + + Examples: + + Setup i18n on a new repository: + + $ mkdir po + $ touch po/pt.po + $ touch po/"$(basename "$PWD")".pot + $ dyn-po4a > po/po4a.cfg + $ po4a po/po4a.cfg + + + Conditionally update the configuration in a Makefile: + + po/po4a.cfg: ALWAYS + dyn-po4a | ifnew $@ + po4a $@ + EOF +} + + +for flag in "$@"; do + case "$flag" in + --) + break + ;; + --help) + usage + help + exit + ;; + *) + ;; + esac +done + +while getopts 'h' flag; do + case "$flag" in + h) + usage + help + exit + ;; + *) + usage >&2 + exit 2 + ;; + esac +done +shift $((OPTIND - 1)) + +. src/lib.sh + + +guess_type() { + case "$1" in + *.md) + echo text + ;; + *.[1-9]*.in) + echo man + ;; + *.html) + echo xhtml + ;; + *) + echo text + ;; + esac +} + + +cat <<-'EOF' + [options] --keep 0 --master-charset UTF-8 --localized-charset UTF-8 + + [po_directory] po + +EOF + +git ls-files | grep -F '.en.' | while read -r file; do + TYPE="$(guess_type "$file")" + # shellcheck disable=2016 + VAR_FILE="$(printf '%s' "$file" | sed 's|\.en\.|.$lang.|')" + # shellcheck disable=2016 + printf '[type: %s] %s $lang:%s\n' "$TYPE" "$file" "$VAR_FILE" +done + +if [ ! -t 0 ]; then + cat +fi -- cgit v1.2.3