Home | History | Annotate | Line # | Download | only in po4a
      1 #!/bin/sh
      2 # SPDX-License-Identifier: 0BSD
      3 
      4 #############################################################################
      5 #
      6 # Updates xz-man.pot and the *.po files, and generates translated man pages.
      7 # These are done using the program po4a. If po4a is missing, it is still
      8 # possible to build the package without translated man pages.
      9 #
     10 #############################################################################
     11 #
     12 # Author: Lasse Collin
     13 #
     14 #############################################################################
     15 
     16 if type po4a > /dev/null 2>&1; then
     17 	:
     18 else
     19 	echo "po4a/update-po: The program 'po4a' was not found." >&2
     20 	echo "po4a/update-po: Translated man pages were not generated." >&2
     21 	exit 1
     22 fi
     23 
     24 if test ! -f po4a.conf; then
     25 	cd `dirname "$0"` || exit 1
     26 	if test ! -f po4a.conf; then
     27 		echo "po4a/update-po: Error: Cannot find po4a.conf." >&2
     28 		exit 1
     29 	fi
     30 fi
     31 
     32 PACKAGE_VERSION=`cd .. && sh build-aux/version.sh` || exit 1
     33 
     34 # Put the author info from the .po files into the header comment of
     35 # the generated man pages.
     36 for FILE in *.po
     37 do
     38 	printf '%s\n.\\"\n' \
     39 'PO4A-HEADER: position=^\.\\" Author; mode=after; beginboundary=^\.\\"$' \
     40 		> "$FILE.authors"
     41 	sed '
     42 		/^[^#]/,$d
     43 		/: 0BSD$/d
     44 		/BSD Zero Clause License/d
     45 		/distributed under the same license/d
     46 		/in the public domain/d
     47 		/The XZ Utils authors and contributors$/d
     48 		/^#$/d
     49 		s/^#/.\\"/
     50 		' "$FILE" >> "$FILE.authors"
     51 done
     52 
     53 # Using --force to get up-to-date version numbers in the output files
     54 # when nothing else has changed. This makes it slower but it's fine
     55 # as long as this isn't run every time when "make" is run at the
     56 # top level directory. (po4a isn't super-fast even without --force).
     57 #
     58 # Make diffing the .pot and .po files easier:
     59 #
     60 #   --porefs file       Put only the input filenames, not line numbers,
     61 #                       into the .pot file. This way they won't get
     62 #                       copied to the .po files either.
     63 #
     64 #   --wrap-po newlines  Wrap msgids only at \n in the .pot file.
     65 #
     66 #   --msgmerge-opt "--no-wrap"
     67 #                       Wrap msgids and msgstrs only at \n in the .po files.
     68 #
     69 # The values from --package-name and --package-version are used to create
     70 # the Project-Id-Version field. It likely makes sense that its value isn't
     71 # identical to the value in the program message translations. In practice
     72 # it seems that the .po files from many (but not all) translators will use
     73 # "xz-man" no matter what is specified here and in xz-man.pot. Thus it's
     74 # best to use "xz-man" here to get the most consistent results.
     75 set -x
     76 po4a --force --verbose \
     77 	--porefs file --wrap-po newlines --msgmerge-opt "--no-wrap" \
     78 	--package-name="xz-man" \
     79 	--package-version="$PACKAGE_VERSION" \
     80 	--copyright-holder="The XZ Utils authors and contributors" \
     81 	po4a.conf
     82 
     83 # Remove the *.po.authors files that were generated above.
     84 # This way they won't get included in distribution tarballs.
     85 rm -f -- *.po.authors
     86 
     87 # Add the customized POT header which contains the SPDX license
     88 # identifier and spells out the license name instead of saying
     89 # "the same license as the XZ Utils package".
     90 mv xz-man.pot xz-man.pot.tmp
     91 cat ../po/xz.pot-header > xz-man.pot
     92 sed '1,/^#$/d' xz-man.pot.tmp >> xz-man.pot
     93 rm xz-man.pot.tmp
     94