diff options
author | EuAndreh <eu@euandre.org> | 2023-04-04 08:33:41 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2023-04-04 08:43:15 -0300 |
commit | 08588f9907299b1a927e281d5c65b46b7cefa427 (patch) | |
tree | 860f8550c2efee35df9bfa1ef56e338f8331c2d1 /v2/aux/po4a-cfg.sh | |
parent | dynamic.mk: Use serve(1) as is (diff) | |
download | euandre.org-08588f9907299b1a927e281d5c65b46b7cefa427.tar.gz euandre.org-08588f9907299b1a927e281d5c65b46b7cefa427.tar.xz |
Revamp v2/
Diffstat (limited to 'v2/aux/po4a-cfg.sh')
-rwxr-xr-x | v2/aux/po4a-cfg.sh | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/v2/aux/po4a-cfg.sh b/v2/aux/po4a-cfg.sh new file mode 100755 index 0000000..b20e303 --- /dev/null +++ b/v2/aux/po4a-cfg.sh @@ -0,0 +1,109 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + aux/po4a-cfg.sh > po/po4a.cfg + aux/po4a-cfg.sh -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 + $ aux/po4a-cfg.sh > po/po4a.cfg + $ po4a po/po4a.cfg + + + Conditionally update the configuration in a Makefile: + + po/po4a.cfg: ALWAYS + @sh aux/po4a-cfg.sh | 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)) + +. aux/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 |