60 lines
2.5 KiB
Bash
60 lines
2.5 KiB
Bash
#!/bin/bash
|
|
|
|
# msgheadermerge expected_older.po expected_newer.po dest-header.po [--mergemode|--newdate|]
|
|
|
|
# This tool merges headers of two .po files and never loses extra info (e. g. plurals).
|
|
|
|
rm -rf {${1%.po},${2%.po}}-msgheadermerge-temp.{merge-dir,order}
|
|
trap "rm -rf {${1%.po},${2%.po}}-msgheadermerge-temp.{merge-dir,order} ${2%.po}-msgheadermerge-tempheader{,1}.po" 0
|
|
|
|
RC=0
|
|
|
|
# Broken pipe is an expected behavior. Redirect stderr to /dev/null.
|
|
msggrep --force-po $1 | msgexec $0-parse ${1%.po}-msgheadermerge-temp 2>/dev/null
|
|
msggrep --force-po $2 | msgexec $0-parse ${2%.po}-msgheadermerge-temp 2>/dev/null
|
|
|
|
# If --swap-plural-forms was used, use plural definition from the other header.
|
|
if test "$6" = --old-plural-forms ; then
|
|
if test -f ${1%.po}-msgheadermerge-temp.merge-dir/Plural-Forms ; then
|
|
if test -f ${2%.po}-msgheadermerge-temp.merge-dir/Plural-Forms ; then
|
|
rm ${2%.po}-msgheadermerge-temp.merge-dir/POT-Creation-Date
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
# Keep original POT date with --mergemode and fail for outdated PO:
|
|
if test "$4" = --mergemode ; then
|
|
rm ${2%.po}-msgheadermerge-temp.merge-dir/POT-Creation-Date
|
|
if test ${2%.po}-msgheadermerge-temp.merge-dir/PO-Revision-Date -ot ${1%.po}-msgheadermerge-temp.merge-dir/PO-Revision-Date ; then
|
|
if test "$5" = --continue ; then
|
|
RC=1
|
|
else
|
|
exit 1
|
|
fi
|
|
fi
|
|
else
|
|
if test "$4" = --newdate ; then
|
|
rm ${1%.po}-msgheadermerge-temp.merge-dir/PO-Revision-Date
|
|
rm ${1%.po}-msgheadermerge-temp.merge-dir/POT-Creation-Date
|
|
else
|
|
if test ${2%.po}-msgheadermerge-temp.merge-dir/POT-Creation-Date -ot ${1%.po}-msgheadermerge-temp.merge-dir/POT-Creation-Date ; then
|
|
rm ${2%.po}-msgheadermerge-temp.merge-dir/POT-Creation-Date
|
|
fi
|
|
if test ${2%.po}-msgheadermerge-temp.merge-dir/PO-Revision-Date -ot ${1%.po}-msgheadermerge-temp.merge-dir/PO-Revision-Date ; then
|
|
rm ${2%.po}-msgheadermerge-temp.merge-dir/PO-Revision-Date
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
# Old project version is the correct one:
|
|
rm -f ${2%.po}-msgheadermerge-temp.merge-dir/Project-Id-Version
|
|
|
|
mv ${2%.po}-msgheadermerge-temp.merge-dir/* ${1%.po}-msgheadermerge-temp.merge-dir/
|
|
cat ${1%.po}-msgheadermerge-temp.order >>${2%.po}-msgheadermerge-temp.order
|
|
|
|
msgmerge --quiet --force-po $2 $0-empty.pot -o ${2%.po}-msgheadermerge-tempheader.po
|
|
msgattrib --no-obsolete --force-po ${2%.po}-msgheadermerge-tempheader.po -o ${2%.po}-msgheadermerge-tempheader1.po
|
|
msgfilter --force-po -i ${2%.po}-msgheadermerge-tempheader1.po -o $3 $0-compose ${1%.po}-msgheadermerge-temp.merge-dir ${2%.po}-msgheadermerge-temp.order
|
|
|
|
exit $RC
|