| 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright © 2010-2017 Dr. Tobias Quathamer <[email protected]> |
| 4 | # 2022,2025,2026 Dr. Helge Kreutzmann <[email protected]> |
| 5 | # |
| 6 | # This program is free software: you can redistribute it and/or modify |
| 7 | # it under the terms of the GNU General Public License as published by |
| 8 | # the Free Software Foundation, either version 3 of the License, or |
| 9 | # (at your option) any later version. |
| 10 | # |
| 11 | # This program is distributed in the hope that it will be useful, |
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | # GNU General Public License for more details. |
| 15 | # |
| 16 | # You should have received a copy of the GNU General Public License |
| 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | |
| 19 | translation="$1" |
| 20 | addendum="$2" |
| 21 | masterfile="$3" |
| 22 | |
| 23 | ismdoc=$(grep -Rl "\.Sh NAME" $masterfile) |
| 24 | |
| 25 | # Use the header up until the first msgid |
| 26 | # and remove the comment character |
| 27 | translators=$(sed '/msgid/q;s/^#\s\+//' "$translation" | |
| 28 | # Throw away the common (non translator) lines |
| 29 | grep -a -v "Macedonian translation of manpages" | |
| 30 | grep -a -v "This file is distributed under the same license as the manpages-l10n package." | |
| 31 | grep -a -v "Copyright © of this file:" | |
| 32 | grep -a -v "FIXME:" | |
| 33 | grep -a -v "msgid" | |
| 34 | grep -a -v '^#[[:space:]]*$' | |
| 35 | # Split lines to extract the name (and e-mail address) |
| 36 | cut -f1 -d","| sed 's/\.$//') |
| 37 | # Determine number of translators |
| 38 | number_translators=$(echo "$translators" | wc -l) |
| 39 | |
| 40 | # Output of common header |
| 41 | echo "PO4A-HEADER:mode=after;position=^\.(TH|Dt);beginboundary=FakePo4aBoundary" > "$addendum" |
| 42 | |
| 43 | # Special case for manpages which use mdoc syntax |
| 44 | if [ $ismdoc ]; then |
| 45 | # MDOC File |
| 46 | echo ".Pp" >> "$addendum" |
| 47 | echo ".Sh ПРЕВОД" >> "$addendum" |
| 48 | else |
| 49 | # Groff file |
| 50 | echo ".PP" >> "$addendum" |
| 51 | echo ".SH ПРЕВОД" >> "$addendum" |
| 52 | fi |
| 53 | echo "Македонскиот превод на оваа рачна страница е создаден од" >> "$addendum" |
| 54 | |
| 55 | # Warn if the translators string is empty |
| 56 | if [ -z "$translators" ]; then |
| 57 | echo "Warning: No translators found for '$translation'." >&2 |
| 58 | fi |
| 59 | # Apply correct formatting, depending on the number of translators |
| 60 | if [ $number_translators -eq 1 ]; then |
| 61 | echo "$translators" >> "$addendum" |
| 62 | fi |
| 63 | if [ $number_translators -eq 2 ]; then |
| 64 | echo "$translators" | head -n1 >> "$addendum" |
| 65 | echo "и" >> "$addendum" |
| 66 | echo "$translators" | tail -n1 >> "$addendum" |
| 67 | fi |
| 68 | if [ $number_translators -ge 3 ]; then |
| 69 | echo "$translators" | head -n$(($number_translators - 2)) | perl -pe "s/$/,/" >> "$addendum" |
| 70 | echo "$translators" | tail -n2 | head -n1 >> "$addendum" |
| 71 | echo "и" >> "$addendum" |
| 72 | echo "$translators" | tail -n1 >> "$addendum" |
| 73 | fi |
| 74 | |
| 75 | # Output of common ending |
| 76 | echo "." >> "$addendum" |
| 77 | |
| 78 | # Special case for manpages which use mdoc syntax |
| 79 | if [ $ismdoc ]; then |
| 80 | # MDOC File |
| 81 | cat license-mdoc.add >> "$addendum" |
| 82 | else |
| 83 | # Groff file |
| 84 | cat license-groff.add >> "$addendum" |
| 85 | fi |