summaryrefslogtreecommitdiffstats
path: root/po/pl/generate-addendum.sh
blob: a8766883d68eb7f689a339b78d2ca361cd198dbb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/sh
#
# Copyright © 2010-2017 Dr. Tobias Quathamer <toddy@debian.org>
#             2022 Dr. Helge Kreutzmann <debian@helgefjell.de>
#
# 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/>.

translation="$1"
addendum="$2"


ismdoc=$(grep -l $translation ../mdoc.cache)

# Use the header up until the first msgid
# and remove the comment character
translators=$(sed '/msgid/q;s/^#\s\+//' "$translation" |
# Throw away the common (non translator) lines
grep -a -v "Polish translation of manpages" |
grep -a -v "This file is distributed under the same license as the manpages-l10n package." |
grep -a -v "Copyright © of this file:" |
grep -a -v "FIXME:" |
grep -a -v "msgid" |
grep -a -v '^#[[:space:]]*$' |
# Split lines to extract the name (and e-mail address)
cut -f1 -d",")
# Determine number of translators
number_translators=$(echo "$translators" | wc -l)

# Output of common header
echo "PO4A-HEADER:mode=after;position=^\.(TH|Dt);beginboundary=FakePo4aBoundary" > "$addendum"

# Special case for manpages which use mdoc syntax
if [ $ismdoc ]; then
    # MDOC File
    echo ".Pp" >> "$addendum"
    echo ".Sh TŁUMACZENIE" >> "$addendum"
else
    # Groff file
    echo ".PP" >> "$addendum"
    echo ".SH TŁUMACZENIE" >> "$addendum"
fi
echo "Autorami polskiego tłumaczenia niniejszej strony podręcznika są:" >> "$addendum"

# Warn if the translators string is empty
if [ -z "$translators" ]; then
	echo "Warning: No translators found for '$translation'." >&2
fi
# Apply correct formatting, depending on the number of translators
if [ $number_translators -eq 1 ]; then
	echo "$translators" >> "$addendum"
fi
if [ $number_translators -eq 2 ]; then
	echo "$translators" | head -n1 >> "$addendum"
	echo "i" >> "$addendum"
	echo "$translators" | tail -n1 >> "$addendum"
fi
if [ $number_translators -ge 3 ]; then
	echo "$translators" | head -n$(($number_translators - 2)) | perl -pe "s/$/,/" >> "$addendum"
	echo "$translators" | tail -n2 | head -n1 >> "$addendum"
	echo "i" >> "$addendum"
	echo "$translators" | tail -n1 >> "$addendum"
fi

# Output of common ending
echo "." >> "$addendum"

# Special case for manpages which use mdoc syntax
if [ $ismdoc ]; then
    # MDOC File
    cat license-mdoc.add >> "$addendum"
else
    # Groff file
    cat license-groff.add >> "$addendum"
fi