summaryrefslogtreecommitdiffstats
path: root/templates/generate-one-template.sh
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 19:43:11 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 19:43:11 +0000
commitfc22b3d6507c6745911b9dfcc68f1e665ae13dbc (patch)
treece1e3bce06471410239a6f41282e328770aa404a /templates/generate-one-template.sh
parentInitial commit. (diff)
downloadmanpages-l10n-fc22b3d6507c6745911b9dfcc68f1e665ae13dbc.tar.xz
manpages-l10n-fc22b3d6507c6745911b9dfcc68f1e665ae13dbc.zip
Adding upstream version 4.22.0.upstream/4.22.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'templates/generate-one-template.sh')
-rwxr-xr-xtemplates/generate-one-template.sh88
1 files changed, 88 insertions, 0 deletions
diff --git a/templates/generate-one-template.sh b/templates/generate-one-template.sh
new file mode 100755
index 00000000..c24fa4d8
--- /dev/null
+++ b/templates/generate-one-template.sh
@@ -0,0 +1,88 @@
+#!/bin/sh
+#
+# Copyright © 2019 Dr. Tobias Quathamer <toddy@debian.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Require one argument (the name of the manpage)
+if [ -z "$1" ]; then
+ echo "Please specify the name of the manpage, e.g. 'arch.1'." >&2
+ exit 1
+fi
+
+# Normalize to the basename of the manpage
+manpage=$(basename $1)
+potfile=$(find man* -type f -name "$manpage.pot")
+
+# If the file exists, create a backup.
+if [ -f "$potfile" ]; then
+ cp "$potfile" backup.pot
+fi
+
+tmp1=$(mktemp)
+tmp2=$(mktemp)
+
+# Get the current time to ensure that all potfiles
+# have the exact same date and time of creation in the header.
+# datetime=$(date --iso-8601=minutes | sed -e "s/T/ /")
+datetime=$(date "+%Y-%m-%d %H:%M%z")
+
+# Find all upstream manpages with a matching name
+potfiles=""
+upstream_manpages=$(find ../upstream/*/ -type f -name "$manpage" | LC_ALL=C sort)
+if [ -z "$upstream_manpages" ]; then
+ echo "The manpage '$manpage' could not be found." >&2
+ exit 1
+fi
+
+# Create pot file
+echo "Generating pot file for manpage '$manpage'"
+
+for upstream_manpage in $upstream_manpages; do
+ # Create a template for each distribution
+ distribution=$(echo $upstream_manpage | cut -d/ -f3)
+
+ potfile=$(mktemp --tmpdir "$distribution.$manpage.XXX.pot")
+ potfiles="$potfiles $potfile"
+ ./generate-template.sh $distribution $manpage > $potfile
+
+ # Ensure the same timestamp
+ if [ -f "$potfile" ]; then
+ sed -i -e "s/^\"POT-Creation-Date: .*$/\"POT-Creation-Date: $datetime\\\\n\"/" "$potfile"
+ fi
+done
+mandir=$(basename $(dirname $upstream_manpage))
+
+# New long extensions are used (e.g. 3type), shorten this to just the number:
+mandir=$(echo $mandir|cut -c 1-4)
+
+# Merge all pot files into one
+msgcat -o "$mandir/$manpage.pot" $potfiles
+
+# Remove random characters from multiple file information
+# and reformat the comment into something more readable, e.g.:
+# "#. #-#-#-#-# archlinux.fclose.3.0bX.pot (PACKAGE VERSION) #-#-#-#-#"
+sed -i -e "s/^#\(\.\?\) #-#-#-#-# \([^.]*\)\.\(.\+\)\.[A-Za-z0-9]\{3\}\.pot/#\1 #-#-#-#-# \2: \3.pot/" "$mandir/$manpage.pot"
+
+# Determine if the only change is the "POT-Creation-Date:" header
+# If so, copy back the backup to revert that change
+if [ -f "$mandir/$manpage.pot" -a -f "backup.pot" ]; then
+ sed -f remove-potcdate.sed < "backup.pot" > "$tmp1"
+ sed -f remove-potcdate.sed < "$mandir/$manpage.pot" > "$tmp2"
+ if cmp "$tmp1" "$tmp2" >/dev/null 2>&1; then
+ mv "backup.pot" "$mandir/$manpage.pot"
+ fi
+fi
+
+rm -f $tmp1 $tmp2 backup.pot $potfiles