1
0
mirror of https://git.tukaani.org/xz.git synced 2026-10-31 03:14:56 +00:00
xz/po4a/update-po
Lasse Collin 814e8828b5
po4a/update-po: Workaround an issue with non-ASCII chars in tables
Non-ASCII chars in tables (.TS ... .TE) result in warnings:

    man --warnings po4a/man/uk/xz.1 > /dev/null
    troff:<standard input>:464: warning: special character 'u0411\[tbl' not defined
    troff:<standard input>:1157: warning: special character 'u044\[tbl' not defined
    troff:<standard input>:1682: warning: special character 'u0434\[tbl' not defined

po4a generates groff Unicode escapes like '\u0435' followed immediately
by '[' in table contexts, causing groff to interpret the full string
'u0435[tbl' as a single special character name. Fix this by inserting
a dummy character (\&) after every Unicode escape so that the bracket
is treated as literal text instead of part of the character name.

Co-authored-by: Otto Kekäläinen <otto@debian.org>
Partially-fixes: https://github.com/tukaani-project/xz/pull/220
2026-05-27 13:00:11 +03:00

100 lines
3.5 KiB
Bash
Executable File

#!/bin/sh
# SPDX-License-Identifier: 0BSD
#############################################################################
#
# Updates xz-man.pot and the *.po files, and generates translated man pages.
# These are done using the program po4a. If po4a is missing, it is still
# possible to build the package without translated man pages.
#
#############################################################################
#
# Author: Lasse Collin
#
#############################################################################
if type po4a > /dev/null 2>&1; then
:
else
echo "po4a/update-po: The program 'po4a' was not found." >&2
echo "po4a/update-po: Translated man pages were not generated." >&2
exit 1
fi
if test ! -f po4a.conf; then
cd `dirname "$0"` || exit 1
if test ! -f po4a.conf; then
echo "po4a/update-po: Error: Cannot find po4a.conf." >&2
exit 1
fi
fi
PACKAGE_VERSION=`cd .. && sh build-aux/version.sh` || exit 1
# Put the author info from the .po files into the header comment of
# the generated man pages.
for FILE in *.po
do
printf '%s\n.\\"\n' \
'PO4A-HEADER: position=^\.\\" Author; mode=after; beginboundary=^\.\\"$' \
> "$FILE.authors"
sed '
/^[^#]/,$d
/: 0BSD$/d
/BSD Zero Clause License/d
/distributed under the same license/d
/in the public domain/d
/The XZ Utils authors and contributors$/d
/^#$/d
s/^#/.\\"/
' "$FILE" >> "$FILE.authors"
done
# Using --force to get up-to-date version numbers in the output files
# when nothing else has changed. This makes it slower but it's fine
# as long as this isn't run every time when "make" is run at the
# top level directory. (po4a isn't super-fast even without --force).
#
# Make diffing the .pot and .po files easier:
#
# --porefs file Put only the input filenames, not line numbers,
# into the .pot file. This way they won't get
# copied to the .po files either.
#
# --wrap-po newlines Wrap msgids only at \n in the .pot file.
#
# --msgmerge-opt "--no-wrap"
# Wrap msgids and msgstrs only at \n in the .po files.
#
# The values from --package-name and --package-version are used to create
# the Project-Id-Version field. It likely makes sense that its value isn't
# identical to the value in the program message translations. In practice
# it seems that the .po files from many (but not all) translators will use
# "xz-man" no matter what is specified here and in xz-man.pot. Thus it's
# best to use "xz-man" here to get the most consistent results.
set -x
po4a --force --verbose \
--porefs file --wrap-po newlines --msgmerge-opt "--no-wrap" \
--package-name="xz-man" \
--package-version="$PACKAGE_VERSION" \
--copyright-holder="The XZ Utils authors and contributors" \
po4a.conf
# Remove the *.po.authors files that were generated above.
# This way they won't get included in distribution tarballs.
rm -f -- *.po.authors
# Non-ASCII characters in table data can cause groff to merge UTF-8 escapes
# with internal table markup like [tbl], creating invalid character names.
# Insert \& (a dummy character) after non-ASCII characters in table data
# rows to prevent this.
perl -i -CSD -pe 's/([^\x00-\x7F])/\1\\&/g if /^\.TS/ .. /^\.TE/' man/*/*.1
# Add the customized POT header which contains the SPDX license
# identifier and spells out the license name instead of saying
# "the same license as the XZ Utils package".
mv xz-man.pot xz-man.pot.tmp
cat ../po/xz.pot-header > xz-man.pot
sed '1,/^#$/d' xz-man.pot.tmp >> xz-man.pot
rm xz-man.pot.tmp