Commit 3ec831a4 authored by anonym's avatar anonym
Browse files

Merge remote-tracking branch 'origin/bugfix/12641+potfile_line_comments' into devel

Fix-committed: #12641
parents df46a556 8391f358
# This shell library is meant to be used with `set -e` and `set -u`. # This shell library is meant to be used with `set -e` and `set -u`.
po_languages () { po_languages () {
for po in po/*.po ; do for po in po/*.po ; do
rel="${po%.po}" rel="${po%.po}"
echo "${rel#po/}" echo "${rel#po/}"
done done
} }
diff_without_pot_creation_date () { diff_without_pot_creation_date () {
old="$1" diff --ignore-matching-lines '^"POT-Creation-Date:' "${@}"
new="$2" }
[ $(diff "$old" "$new" | grep -Ec '^>') -eq 1 -a \ diff_without_pot_creation_date_and_comments () {
$(diff "$old" "$new" | grep -Ec '^<') -eq 1 -a \ diff --ignore-matching-lines '^"POT-Creation-Date:' \
$(diff "$old" "$new" | grep -Ec '^[<>] "POT-Creation-Date:') -eq 2 ] --ignore-matching-lines '^#: .*:[0-9]\+$' "${@}"
} }
intltool_update_po () { intltool_update_po () {
( (
cd po cd po
for locale in "$@" ; do for locale in "$@" ; do
intltool-update --dist --gettext-package=tails $locale -o ${locale}.po.new intltool-update --dist --gettext-package=tails $locale -o ${locale}.po.new
...@@ -25,11 +25,14 @@ intltool_update_po () { ...@@ -25,11 +25,14 @@ intltool_update_po () {
[ -f ${locale}.po ] || continue [ -f ${locale}.po ] || continue
[ -f ${locale}.po.new ] || continue [ -f ${locale}.po.new ] || continue
if diff_without_pot_creation_date "${locale}.po" "${locale}.po.new"; then if [ "${FORCE}" = yes ]; then
echo "${locale}: Only header changes in potfile, delete new PO file." echo "Force-updating '${locale}.po'."
rm ${locale}.po.new mv ${locale}.po.new ${locale}.po
elif diff_without_pot_creation_date -q "${locale}.po" "${locale}.po.new"; then
echo "${locale}: Only header changes in PO file: keeping the old one"
rm ${locale}.po.new
else else
echo "${locale}: Real changes in potfile: substitute old PO file." echo "${locale}: Real changes in PO file: switching to the updated one"
mv ${locale}.po.new ${locale}.po mv ${locale}.po.new ${locale}.po
fi fi
done done
......
...@@ -4,20 +4,20 @@ set -e ...@@ -4,20 +4,20 @@ set -e
set -u set -u
PERL_PROGS="/usr/local/bin/tails-security-check \ PERL_PROGS="/usr/local/bin/tails-security-check \
/usr/local/lib/tails-htp-notify-user \ /usr/local/lib/tails-htp-notify-user \
/usr/local/lib/tails-virt-notify-user" /usr/local/lib/tails-virt-notify-user"
PYTHON_PROGS="/etc/whisperback/config.py \ PYTHON_PROGS="/etc/whisperback/config.py \
/usr/local/bin/tails-about /usr/local/sbin/tails-additional-software" /usr/local/bin/tails-about /usr/local/sbin/tails-additional-software"
SHELL_PROGS="/etc/NetworkManager/dispatcher.d/60-tor-ready.sh \ SHELL_PROGS="/etc/NetworkManager/dispatcher.d/60-tor-ready.sh \
/usr/local/bin/electrum \ /usr/local/bin/electrum \
/usr/local/bin/keepassx \ /usr/local/bin/keepassx \
/usr/local/bin/tails-upgrade-frontend-wrapper \ /usr/local/bin/tails-upgrade-frontend-wrapper \
/usr/local/lib/tails-spoof-mac \ /usr/local/lib/tails-spoof-mac \
/usr/local/bin/tor-browser \ /usr/local/bin/tor-browser \
/usr/local/sbin/unsafe-browser" /usr/local/sbin/unsafe-browser"
JAVASCRIPT_PROGS=" \ JAVASCRIPT_PROGS=" \
/usr/share/gnome-shell/extensions/shutdown-helper@tails.boum.org/extension.js \ /usr/share/gnome-shell/extensions/shutdown-helper@tails.boum.org/extension.js \
/usr/share/gnome-shell/extensions/torstatus@tails.boum.org/extension.js \ /usr/share/gnome-shell/extensions/torstatus@tails.boum.org/extension.js \
" "
LOCALE_BASEDIR=config/chroot_local-includes/usr/share/locale LOCALE_BASEDIR=config/chroot_local-includes/usr/share/locale
...@@ -28,96 +28,124 @@ LOCALE_BASEDIR=config/chroot_local-includes/usr/share/locale ...@@ -28,96 +28,124 @@ LOCALE_BASEDIR=config/chroot_local-includes/usr/share/locale
### Functions ### Functions
prog_potfile () { normalize_pot () {
prog=$1 sed --regexp-extended \
-i 's@^"Content-Type: text/plain; charset=CHARSET\\n"@"Content-Type: text/plain; charset=UTF-8\\n"@' \
progpath="config/chroot_local-includes$prog" "${@}"
case $prog in
/usr/share/gnome-shell/extensions/shutdown-helper@tails.boum.org/extension.js)
domain=shutdown-helper-extension.js
;;
*)
domain=$(basename $prog)
;;
esac
echo "tmp/pot/${domain}.pot"
} }
refresh_pot () { prog_potfile () {
prog=$1 prog=$1
proglang=$2
progpath="config/chroot_local-includes$prog"
progpath="config/chroot_local-includes$prog" case $prog in
pot=$(prog_potfile $prog) /usr/share/gnome-shell/extensions/shutdown-helper@tails.boum.org/extension.js)
domain=shutdown-helper-extension.js
mkdir -p "$(dirname $pot)" ;;
*)
domain=$(basename $prog)
;;
esac
echo "tmp/pot/${domain}.pot"
}
if [ -e "${progpath}" ]; then create_pot () {
xgettext --language="${proglang}" --from-code=UTF-8 \ prog=$1
-o "${pot}" "${progpath}" proglang=$2
sed -i "s@^\"Content-Type: text/plain\; charset=CHARSET\\\n\"@\"Content-Type: text/plain\; charset=UTF-8\\\n\"@" "${pot}" progpath="config/chroot_local-includes${prog}"
fi if [ -e "${progpath}" ]; then
pot="$(prog_potfile "${prog}")"
mkdir -p "$(dirname ${pot})"
xgettext --language="${proglang}" --from-code=UTF-8 \
-o "${pot}" "${progpath}"
normalize_pot "${pot}"
else
echo "error: We are supposed to create a POT file for '${prog}'" \
"but '${progpath}' does not exist"
exit 1
fi
} }
po_file () { po_file () {
locale=$1 locale=$1
echo "po/${locale}.po" echo "po/${locale}.po"
} }
mo_file () { mo_file () {
locale=$1 locale=$1
echo "${LOCALE_BASEDIR}/${locale}/LC_MESSAGES/tails.mo" echo "${LOCALE_BASEDIR}/${locale}/LC_MESSAGES/tails.mo"
} }
refresh_mo () { refresh_mo () {
for locale in "$@" ; do for locale in "$@" ; do
po=$(po_file $locale) po=$(po_file $locale)
mo=$(mo_file $locale) mo=$(mo_file $locale)
mkdir -p $(dirname "$mo") mkdir -p $(dirname "$mo")
msgfmt -o "${mo}" "${po}" msgfmt -o "${mo}" "${po}"
done done
} }
no_left_out_files () { no_left_out_files () {
(cd po && intltool-update --maintain) (cd po && intltool-update --maintain)
[ ! -e po/missing ] || return 1 [ ! -e po/missing ] || return 1
return 0 return 0
} }
intltool_update_pot () { intltool_update_pot () {
( (
cd po cd po
cp -a tails.pot tails.pot.orig cp -a tails.pot tails.pot.orig
intltool-update --pot --gettext-package=tails intltool-update --pot --gettext-package=tails
normalize_pot tails.pot tails.pot.orig
if diff_without_pot_creation_date tails.pot.orig tails.pot ; then
echo "Only header changes in tails.pot, restoring the old one." if [ "${FORCE}" = yes ]; then
mv tails.pot.orig tails.pot echo "Force-updating 'tails.pot'."
else rm tails.pot.orig
echo "Real changes in tails.pot: keeping the updated one." elif diff_without_pot_creation_date_and_comments -q tails.pot.orig tails.pot; then
rm tails.pot.orig echo "Only header or comment changes in tails.pot: keeping the old one"
fi mv tails.pot.orig tails.pot
) else
echo "Real changes in tails.pot: switching to the updated one"
rm tails.pot.orig
fi
)
} }
intltool_merge () { intltool_merge () {
grep -E --no-filename '[^ #]*\.(desktop|directory)\.in$' po/POTFILES.in \ grep -E --no-filename '[^ #]*\.(desktop|directory)\.in$' po/POTFILES.in \
| while read infile ; do | while read infile ; do
intltool-merge --quiet --desktop-style --utf8 \ intltool-merge --quiet --desktop-style --utf8 \
po "$infile" "${infile%.in}" po "$infile" "${infile%.in}"
done done
} }
### Main ### Main
# Schedule clean up
trap "rm -fr tmp/pot po/*.new po/*.orig" EXIT
FORCE=no
while [ -n "${@:-}" ]; do
case "${1:-}" in
'--force')
FORCE=yes
;;
*)
echo "Unknown option: ${1}"
exit 1
;;
esac
shift
done
# Update POT files # Update POT files
mkdir -p tmp/pot mkdir -p tmp/pot
for prog in $PERL_PROGS ; do refresh_pot $prog Perl ; done for prog in $PERL_PROGS ; do create_pot $prog Perl ; done
for prog in $PYTHON_PROGS ; do refresh_pot $prog Python ; done for prog in $PYTHON_PROGS ; do create_pot $prog Python ; done
for prog in $SHELL_PROGS ; do refresh_pot $prog Shell ; done for prog in $SHELL_PROGS ; do create_pot $prog Shell ; done
for prog in $JAVASCRIPT_PROGS ; do refresh_pot $prog JavaScript ; done for prog in $JAVASCRIPT_PROGS ; do create_pot $prog JavaScript ; done
intltool_update_pot intltool_update_pot
# If left out files are detected, intltool-update --maintain writes # If left out files are detected, intltool-update --maintain writes
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment