2009-02-12 00:40:55 +01:00
|
|
|
#! /bin/bash
|
|
|
|
|
2020-06-02 02:40:50 +02:00
|
|
|
echo "No translation-update-upstream data available. Keeping existing translation."
|
|
|
|
exit 0
|
|
|
|
|
2009-02-12 00:40:55 +01:00
|
|
|
set -o errexit
|
2009-10-21 02:01:28 +02:00
|
|
|
shopt -s nullglob
|
2009-02-12 00:40:55 +01:00
|
|
|
|
|
|
|
if test "$1" = "--help" ; then
|
|
|
|
echo "Upstream translation update tool works in top directory of unpacked source code."
|
2010-06-04 12:49:48 +02:00
|
|
|
echo "Usage: $0 [translation_directory] [translation_domain] [command to create pot file]"
|
2009-02-12 00:40:55 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Update all known mechanisms to add language:
|
|
|
|
function linguas_update {
|
2010-09-16 12:30:22 +02:00
|
|
|
if test -f LINGUAS -o -f ../po/LINGUAS ; then
|
|
|
|
if test -f LINGUAS ; then
|
2019-01-08 16:28:54 +01:00
|
|
|
touch -r LINGUAS translation-update-upstream-tmp-stamp
|
2010-09-16 12:30:22 +02:00
|
|
|
if sed '/^#/d' <LINGUAS | grep -q '[a-zA-Z0-9] [a-z]' ; then
|
|
|
|
echo "Adding $LNG to LINGUAS in to a list in single-line list mode."
|
|
|
|
sed -i "s/^[^#].* [a-z].*\$/& $LNG/" LINGUAS
|
|
|
|
else
|
|
|
|
echo "Adding $LNG to LINGUAS."
|
|
|
|
echo $LNG >>LINGUAS
|
|
|
|
fi
|
2019-01-08 16:28:54 +01:00
|
|
|
touch -r translation-update-upstream-tmp-stamp LINGUAS
|
|
|
|
rm translation-update-upstream-tmp-stamp
|
2010-09-16 12:30:22 +02:00
|
|
|
else
|
|
|
|
echo "Not adding $LNG to LINGUAS - secondary domain, global LINGUAS."
|
2009-02-12 00:40:55 +01:00
|
|
|
fi
|
2010-09-16 12:30:22 +02:00
|
|
|
else
|
|
|
|
if test -f $OLDPWD/configure.ac ; then
|
|
|
|
if grep -q 'ALL_LINGUAS=' $OLDPWD/configure.ac ; then
|
|
|
|
echo "Adding $LNG to configure.ac."
|
2019-01-08 16:28:54 +01:00
|
|
|
touch -r $OLDPWD/configure.ac translation-update-upstream-tmp-stamp
|
2010-09-16 12:30:22 +02:00
|
|
|
sed -i 's/ALL_LINGUAS="/&'$LNG' /;s/\(ALL_LINGUAS=\)\([^"]\|$\)/\1"'$LNG' "\2/' $OLDPWD/configure.ac
|
2019-01-08 16:28:54 +01:00
|
|
|
touch -r translation-update-upstream-tmp-stamp $OLDPWD/configure.ac
|
|
|
|
rm translation-update-upstream-tmp-stamp
|
2010-09-16 12:30:22 +02:00
|
|
|
fi
|
2010-06-14 20:59:17 +02:00
|
|
|
fi
|
2010-09-16 12:30:22 +02:00
|
|
|
if test -f $OLDPWD/configure.in ; then
|
|
|
|
if grep -q 'ALL_LINGUAS=' $OLDPWD/configure.in ; then
|
|
|
|
echo "Adding $LNG to configure.in."
|
2019-01-08 16:28:54 +01:00
|
|
|
touch -r $OLDPWD/configure.in translation-update-upstream-tmp-stamp
|
2010-09-16 12:30:22 +02:00
|
|
|
sed -i 's/ALL_LINGUAS="/&'$LNG' /;s/\(ALL_LINGUAS=\)\([^"]\|$\)/\1"'$LNG' "\2/' $OLDPWD/configure.in
|
2019-01-08 16:28:54 +01:00
|
|
|
touch -r translation-update-upstream-tmp-stamp $OLDPWD/configure.in
|
|
|
|
rm translation-update-upstream-tmp-stamp
|
2010-09-16 12:30:22 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if test -f $OLDPWD/configure ; then
|
|
|
|
if grep -q 'ALL_LINGUAS=' $OLDPWD/configure ; then
|
|
|
|
echo "Adding $LNG to configure."
|
2019-01-08 16:28:54 +01:00
|
|
|
touch -r $OLDPWD/configure translation-update-upstream-tmp-stamp
|
2010-09-16 12:30:22 +02:00
|
|
|
sed -i 's/ALL_LINGUAS="/&'$LNG' /;s/\(ALL_LINGUAS=\)\([^"]\|$\)/\1"'$LNG' "\2/' $OLDPWD/configure
|
2019-01-08 16:28:54 +01:00
|
|
|
touch -r translation-update-upstream-tmp-stamp $OLDPWD/configure
|
|
|
|
rm translation-update-upstream-tmp-stamp
|
2010-09-16 12:30:22 +02:00
|
|
|
fi
|
2009-02-12 00:40:55 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2009-10-21 02:01:28 +02:00
|
|
|
DOMAIN=$2
|
2018-07-09 18:51:50 +02:00
|
|
|
USE_MESON=false
|
|
|
|
if test -f meson.build -a ! \( -f ${1:-po}/Makefile.in.in -o -f ${1:-po}/Makefile.in -o -f ${1:-po}/Makefile \) ; then
|
|
|
|
echo "Switching to meson style pot file extraction." >&2
|
|
|
|
USE_MESON=true
|
|
|
|
if test -z "$DOMAIN" ; then
|
|
|
|
MESON_PROJECT="$(sed -n "/^project(/,+1{1{h;d};2{x;G}};s/^project[[:space:]]*([[:space:]]*'\([^']*\)'.*/\1/p" <meson.build)"
|
|
|
|
DOMAIN="$(sed -n "s/meson.project_name[[:space:]]*([[:space:]]*)/'$MESON_PROJECT'/g;s/.*\.set_quoted[[:space:]]*('GETTEXT_PACKAGE',[[:space:]]'\([^']*\)').*/\1/p" <meson.build)"
|
|
|
|
if test -z "$DOMAIN" ; then
|
|
|
|
if ! grep -q GETTEXT_PACKAGE meson.build ; then
|
|
|
|
DOMAIN="$MESON_PROJECT"
|
|
|
|
else
|
|
|
|
echo "Error: Gettext domain cannot be determined." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
2020-06-02 02:40:50 +02:00
|
|
|
USE_INTLTOOL=false
|
|
|
|
if test -f configure.ac ; then
|
|
|
|
if grep PROG_INTLTOOL configure.ac ; then
|
|
|
|
USE_INTLTOOL=true
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if test -f configure.in ; then
|
|
|
|
if grep PROG_INTLTOOL configure.in ; then
|
|
|
|
USE_INTLTOOL=true
|
|
|
|
fi
|
|
|
|
fi
|
2018-07-09 18:51:50 +02:00
|
|
|
DIR=${1:-po}
|
2009-02-12 00:40:55 +01:00
|
|
|
|
2010-06-04 12:49:48 +02:00
|
|
|
if test -z "$3" ; then
|
2018-07-09 18:51:50 +02:00
|
|
|
if $USE_MESON ; then
|
|
|
|
if test -f POTFILES ; then
|
|
|
|
POTFILES="$PWD/${1:-po}/POTFILES"
|
|
|
|
else
|
|
|
|
POTFILES="$PWD/${1:-po}/POTFILES.in"
|
|
|
|
fi
|
|
|
|
xgettext --package-name="$DOMAIN"\
|
|
|
|
-p "$PWD" -f "$POTFILES" -D "$PWD"\
|
|
|
|
-k_ -o "$PWD/${1:-po}/$DOMAIN.pot"\
|
|
|
|
--keyword=NC_:1c,2\
|
|
|
|
--flag=g_strdup_printf:1:c-format\
|
|
|
|
--flag=g_set_error:4:c-format\
|
|
|
|
--flag=g_dngettext:2:pass-c-format\
|
|
|
|
--flag=g_string_printf:2:c-format\
|
|
|
|
--add-comments\
|
|
|
|
--from-code=UTF-8\
|
|
|
|
--keyword=C_:1c,2\
|
|
|
|
--flag=N_:1:pass-c-format\
|
|
|
|
--flag=g_string_append_printf:2:c-format\
|
|
|
|
--flag=C_:2:pass-c-format\
|
|
|
|
--keyword=N_\
|
|
|
|
--flag=g_error_new:3:c-format\
|
|
|
|
--flag=NC_:2:pass-c-format\
|
|
|
|
--keyword=g_dngettext:2,3\
|
|
|
|
--keyword=g_dpgettext2:2c,3\
|
|
|
|
--keyword=_\
|
|
|
|
--keyword=g_dcgettext:2
|
|
|
|
cd $DIR
|
2010-06-04 12:49:48 +02:00
|
|
|
else
|
2018-07-09 18:51:50 +02:00
|
|
|
cd $DIR
|
2020-06-02 02:40:50 +02:00
|
|
|
if $USE_INTLTOOL ; then
|
|
|
|
if test -z "$DOMAIN" ; then
|
|
|
|
intltool-update --pot
|
|
|
|
else
|
|
|
|
intltool-update --gettext-package=$DOMAIN --pot
|
|
|
|
fi
|
2018-07-09 18:51:50 +02:00
|
|
|
else
|
2020-06-02 02:40:50 +02:00
|
|
|
# Fallback: use xgettext with default options except those that we
|
|
|
|
# cannot guess (it can stil fail, as options can be customized).
|
|
|
|
if test -z "$DOMAIN" ; then
|
|
|
|
## Ugly hack! intltool could return invalid po, but its
|
|
|
|
## FindPackageName() can guess domain. Call it to get it.
|
|
|
|
intltool-update --pot
|
|
|
|
for POT in *.pot ; do
|
|
|
|
DOMAIN=${POT%.pot}
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
xgettext --default-domain="$DOMAIN" --directory="$OLDPWD" \
|
|
|
|
--add-comments=TRANSLATORS: --from-code=UTF-8 --keyword=_ --keyword=N_ --keyword=C_:1c,2 --keyword=NC_:1c,2 --keyword=g_dngettext:2,3 --add-comments \
|
|
|
|
--files-from=./POTFILES.in
|
|
|
|
mv "$DOMAIN.po" "$DOMAIN.pot"
|
2018-07-09 18:51:50 +02:00
|
|
|
fi
|
2010-06-04 12:49:48 +02:00
|
|
|
fi
|
2009-10-21 02:01:28 +02:00
|
|
|
else
|
2010-06-04 12:49:48 +02:00
|
|
|
eval $3
|
2009-10-21 02:01:28 +02:00
|
|
|
fi
|
2009-02-12 00:40:55 +01:00
|
|
|
|
|
|
|
POT_NOT_UNIQUE=false
|
2011-09-07 16:12:07 +02:00
|
|
|
NO_POT=true
|
2009-02-12 00:40:55 +01:00
|
|
|
for POT in *.pot ; do
|
2011-09-07 16:12:07 +02:00
|
|
|
MISSING=true
|
2009-02-12 00:40:55 +01:00
|
|
|
if $POT_NOT_UNIQUE ; then
|
|
|
|
echo "ERROR: Directory $DIR contains more than one .pot file."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
POT_NOT_UNIQUE=true
|
|
|
|
DOMAIN=${POT%.pot}
|
|
|
|
|
|
|
|
# STRING_COLLECT_MODE is a special mode used during string
|
|
|
|
# collection. STRING_COLLECT_DIR must be set as well.
|
|
|
|
if test "$STRING_COLLECT_MODE" = 1 ; then
|
|
|
|
mkdir $STRING_COLLECT_DIR/$DOMAIN
|
|
|
|
cp -a $POT $STRING_COLLECT_DIR/$DOMAIN
|
|
|
|
cp -a *.po $STRING_COLLECT_DIR/$DOMAIN
|
|
|
|
else
|
2009-10-21 02:01:28 +02:00
|
|
|
if test -d @DATADIR@/translation-update-upstream ; then
|
2010-06-04 12:49:48 +02:00
|
|
|
if test -d @DATADIR@/translation-update-upstream/po/$DOMAIN ; then
|
|
|
|
for PO_PATH in @DATADIR@/translation-update-upstream/po/$DOMAIN/*.po ; do
|
2009-02-12 00:40:55 +01:00
|
|
|
PO=${PO_PATH##*/}
|
|
|
|
LNG=${PO%.po}
|
|
|
|
if test -f $PO ; then
|
2011-09-07 14:45:34 +02:00
|
|
|
if test "$SKIP_TUU" = true ; then
|
|
|
|
echo "SKIP_TUU is set. Skipping update of $PO."
|
|
|
|
continue
|
|
|
|
fi
|
2009-02-12 00:40:55 +01:00
|
|
|
echo "Updating $PO using translation-update-upstream."
|
2011-09-07 14:45:34 +02:00
|
|
|
echo "(You can skip update by setting environment variable SKIP_TUU=true.)"
|
2009-02-12 00:40:55 +01:00
|
|
|
# PO_PATH is first: Update any string, even if it was already translated.
|
|
|
|
# Swap $PO_PATH and $PO to disable this behavior.
|
|
|
|
msgcat --use-first $PO_PATH $PO -o $PO.new
|
2009-10-21 02:01:28 +02:00
|
|
|
# Return .po file notes that are not present in the update file.
|
2020-06-02 02:40:50 +02:00
|
|
|
## In theory, we should call msgmerge here, as the
|
|
|
|
## imported file might be outdated. But we have to live
|
|
|
|
## with the fact that the pot file heuristic above
|
|
|
|
## might be incorrect, and the generated pot file is
|
|
|
|
## incomplete. Never make things worse, and skip
|
|
|
|
## msgmerge. Superfluous strings are better than
|
|
|
|
## deleted strings.
|
|
|
|
## In time of writing the priginal code, --compendium
|
|
|
|
## worked around the fact that msgcat prefers empty
|
|
|
|
## string from the first file over translated string
|
|
|
|
## from the second file. Now msgcat behaves logically,
|
|
|
|
## so this step is not needed.
|
|
|
|
#msgmerge --no-fuzzy-matching --compendium=$PO_PATH -o $PO.new2 $PO.new $POT
|
2009-10-21 02:01:28 +02:00
|
|
|
# And finally, synthesize header that not change every time.
|
2020-06-02 02:40:50 +02:00
|
|
|
#if @LIBEXECDIR@/translation-update-upstream/msgheadermerge $PO $PO.new2 $PO.header --mergemode ; then
|
|
|
|
if @LIBEXECDIR@/translation-update-upstream/msgheadermerge $PO $PO.new $PO.header --mergemode ; then
|
|
|
|
#msgcat --use-first $PO.header $PO.new2 -o $PO
|
|
|
|
msgcat --use-first $PO.header -o $PO
|
|
|
|
#rm $PO.new $PO.new2 $PO.header
|
|
|
|
rm $PO.new $PO.header
|
2009-10-21 02:01:28 +02:00
|
|
|
else
|
2020-06-02 02:40:50 +02:00
|
|
|
#rm $PO.new $PO.new2
|
|
|
|
rm $PO.new
|
2009-10-21 02:01:28 +02:00
|
|
|
echo "WARNING: Update of $PO for $DOMAIN is older than data in package. Skipping."
|
|
|
|
fi
|
2009-02-12 00:40:55 +01:00
|
|
|
else
|
|
|
|
echo "Adding $PO from translation-update-upstream."
|
|
|
|
cp -a $PO_PATH $PO
|
|
|
|
linguas_update
|
|
|
|
fi
|
|
|
|
done
|
2010-06-04 12:49:48 +02:00
|
|
|
MISSING=false
|
|
|
|
fi
|
|
|
|
if test -d @DATADIR@/translation-update-upstream/po-mandatory/$DOMAIN ; then
|
|
|
|
for PO_PATH in @DATADIR@/translation-update-upstream/po-mandatory/$DOMAIN/*.po ; do
|
|
|
|
PO=${PO_PATH##*/}
|
|
|
|
LNG=${PO%.po}
|
|
|
|
if test -f $PO ; then
|
2011-09-07 14:45:34 +02:00
|
|
|
if test "$SKIP_TUU" = true ; then
|
|
|
|
echo "SKIP_TUU is set. Skipping update of $PO."
|
|
|
|
continue
|
|
|
|
fi
|
2010-06-04 12:49:48 +02:00
|
|
|
echo "Updating $PO using translation-update-upstream mandatory source."
|
2011-09-07 14:45:34 +02:00
|
|
|
echo "(You can skip update by setting environment variable SKIP_TUU=true.)"
|
2010-06-04 12:49:48 +02:00
|
|
|
# PO_PATH is first: Update any string, even if it was already translated.
|
|
|
|
# Swap $PO_PATH and $PO to disable this behavior.
|
|
|
|
msgcat --use-first $PO_PATH $PO -o $PO.new
|
|
|
|
# Return .po file notes that are not present in the update file.
|
2020-06-02 02:40:50 +02:00
|
|
|
## In theory, we should call msgmerge here, as the
|
|
|
|
## imported file might be outdated. But we have to live
|
|
|
|
## with the fact that the pot file heuristic above
|
|
|
|
## might be incorrect, and the generated pot file is
|
|
|
|
## incomplete. Never make things worse, and skip
|
|
|
|
## msgmerge. Superfluous strings are better than
|
|
|
|
## deleted strings.
|
|
|
|
## In time of writing the priginal code, --compendium
|
|
|
|
## worked around the fact that msgcat prefers empty
|
|
|
|
## string from the first file over translated string
|
|
|
|
## from the second file. Now msgcat behaves logically,
|
|
|
|
## so this step is not needed.
|
|
|
|
#msgmerge --no-fuzzy-matching --compendium=$PO_PATH -o $PO.new2 $PO.new $POT
|
2010-06-04 12:49:48 +02:00
|
|
|
# And finally, synthesize header that not change every time.
|
2020-06-02 02:40:50 +02:00
|
|
|
#if ! @LIBEXECDIR@/translation-update-upstream/msgheadermerge $PO $PO.new2 $PO.header --mergemode --continue ; then
|
|
|
|
if ! @LIBEXECDIR@/translation-update-upstream/msgheadermerge $PO $PO.new $PO.header --mergemode --continue ; then
|
2010-06-04 12:49:48 +02:00
|
|
|
echo "WARNING: Mandatory update of $PO for $DOMAIN is older than data in package or upstream snapshot. Using anyway!"
|
|
|
|
fi
|
2020-06-02 02:40:50 +02:00
|
|
|
#msgcat --use-first $PO.header $PO.new2 -o $PO
|
|
|
|
msgcat --use-first $PO.header $PO.new -o $PO
|
|
|
|
#rm $PO.new $PO.new2 $PO.header
|
|
|
|
rm $PO.new $PO.header
|
2010-06-04 12:49:48 +02:00
|
|
|
else
|
|
|
|
echo "Adding $PO from translation-update-upstream mandatory source."
|
|
|
|
cp -a $PO_PATH $PO
|
|
|
|
linguas_update
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
MISSING=false
|
|
|
|
fi
|
2011-09-07 16:12:07 +02:00
|
|
|
if $MISSING ; then
|
|
|
|
echo "WARNING: Missing $DOMAIN in translation-update-upstream configuration! No updates available."
|
|
|
|
fi
|
2009-02-12 00:40:55 +01:00
|
|
|
else
|
|
|
|
echo "ERROR: Package translation-update-upstream is not installed. Please update your BuildRequires!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2011-09-07 16:12:07 +02:00
|
|
|
NO_POT=false
|
2009-02-12 00:40:55 +01:00
|
|
|
done
|
2011-09-07 16:12:07 +02:00
|
|
|
if $NO_POT ; then
|
|
|
|
echo "ERROR: Pot file was not created. Please fix or set command line arguments properly!"
|
2011-09-07 14:45:34 +02:00
|
|
|
exit 1
|
|
|
|
fi
|