diff --git a/suse_update_desktop_file.sh b/suse_update_desktop_file.sh index 9609e54..cd6fbcc 100644 --- a/suse_update_desktop_file.sh +++ b/suse_update_desktop_file.sh @@ -238,6 +238,24 @@ if [ -n "$FILE_DOCPATH" ] ; then fi fi +#BEGIN Upstreaming help +DESKTOP_NAME=${APPLICATION##*/} +DESKTOP_PATH=${APPLICATION%$DESKTOP_NAME} +DESKTOP_NAME=${DESKTOP_NAME%.desktop} +if test -z "$DESKTOP_PATH" ; then + DESKTOP_PATH=$RPM_BUILD_ROOT/usr/share/applications/ +fi +# Get rid ugly but common slash duplication +DESKTOP_PATH=${DESKTOP_PATH//\/\//\/} + +# Set working directory always to $RPM_BUILD_DIR. It prevents placing +# the files inside BUILDROOT. And some packages are confused by new +# desktop files placed to its build directory. +SUDF_DIR=$RPM_BUILD_DIR + +mkdir -p $SUDF_DIR/suse_update_desktop_file/update-desktop-files/$DESKTOP_NAME +cp -v "$FILE" $SUDF_DIR/suse_update_desktop_file/update-desktop-files/$DESKTOP_NAME/$DESKTOP_NAME-upstream.desktop +#END Upstreaming help # # update Categories # @@ -355,6 +373,123 @@ if [ "$COMMENT" != "no" ]; then fi fi +#BEGIN Upstreaming help +GENERIC_CHANGES=false +TRANSLATION_CHANGES=false +shopt -s nullglob +cp -v "$FILE" $SUDF_DIR/suse_update_desktop_file/update-desktop-files/$DESKTOP_NAME/$DESKTOP_NAME-downstream-no-translation.desktop +# Insert translations from the downstream +ORIG_DIR=$PWD +cd $SUDF_DIR/suse_update_desktop_file/update-desktop-files/$DESKTOP_NAME +if [ "$I18N" != "no" ]; then + sed "s@^Name=@_&Name($DESKTOP_NAME.desktop): @;s@^GenericName=@_&GenericName($DESKTOP_NAME.desktop): @;s@^Comment=@_&Comment($DESKTOP_NAME.desktop): @;s@^Keywords=@_&Keywords($DESKTOP_NAME.desktop): @" $FILE >$DESKTOP_NAME-downstream-no-translation-desktop_translations.desktop + intltool-merge /usr/share/desktop-translations/desktop_translations $DESKTOP_NAME-downstream-no-translation-desktop_translations.desktop $DESKTOP_NAME-downstream-translated-raw.desktop -d -u + sed -i "s@^Name=Name($DESKTOP_NAME.desktop): @Name=@;s@^GenericName=GenericName($DESKTOP_NAME.desktop): @GenericName=@;s@^Comment=Comment($DESKTOP_NAME.desktop): @Comment=@;s@^Keywords=Keywords($DESKTOP_NAME.desktop): @Keywords=@" $DESKTOP_NAME-downstream-translated-raw.desktop + ${0%.sh}_process_translations.py $DESKTOP_NAME + cp -a -v $DESKTOP_NAME-downstream-translated.desktop $FILE + if ! diff -u $DESKTOP_NAME-upstream.desktop $DESKTOP_NAME-downstream-translated.desktop >$DESKTOP_NAME-downstream-directly-translated.diff ; then + TRANSLATION_CHANGES=true + fi + sed -i "1,2s/$DESKTOP_NAME-\(upstream\|downstream-translated\).desktop/$DESKTOP_NAME.desktop/" $DESKTOP_NAME-downstream-directly-translated.diff + for DESKTOP in $DESKTOP_NAME-upstream $DESKTOP_NAME-downstream-no-translation ; do + sed "/\(Name\|GenericName\|Comment\|Keywords\)\[/d;s@^Name=@_Name=@;s@^GenericName=@_GenericName=@;s@^Comment=@_Comment=@;s@^Keywords=@_Keywords=@" $DESKTOP.desktop >$DESKTOP.desktop.in + done + if ! diff -u $DESKTOP_NAME-upstream.desktop.in $DESKTOP_NAME-downstream-no-translation.desktop.in >$DESKTOP_NAME-downstream-in-translated.diff ; then + GENERIC_CHANGES=true + fi + sed -i "1,2s/$DESKTOP_NAME-\(upstream\|downstream-no-translation\).desktop.in/$DESKTOP_NAME.desktop.in/" $DESKTOP_NAME-downstream-in-translated.diff + mkdir po + intltool-extract --type=gettext/ini $DESKTOP_NAME-downstream-no-translation-desktop_translations.desktop + xgettext --default-domain=$DESKTOP_NAME --add-comments --keyword=_ --keyword=N_ --keyword=U_ $DESKTOP_NAME-downstream-no-translation-desktop_translations.desktop.h -o po/$DESKTOP_NAME.pot + for PO in /usr/share/desktop-translations/desktop_translations/*.po ; do + LNG=${PO##*/} + LNG=${LNG%.po} + msgmerge $PO po/$DESKTOP_NAME.pot -o po/$LNG-pre.po + if test -f po/$LNG-pre.po ; then + msgattrib --no-obsolete po/$LNG-pre.po -o po/$LNG.po + fi + sed -i "s@\"\(Name\|GenericName\|Comment\|Keywords\)($DESKTOP_NAME.desktop): @\"@" po/$LNG.po + rm po/$LNG-pre.po + done + sed -i "s@\"\(Name\|GenericName\|Comment\|Keywords\)($DESKTOP_NAME.desktop): @\"@" po/$DESKTOP_NAME.pot + rm $DESKTOP_NAME-downstream-no-translation-desktop_translations.desktop $DESKTOP_NAME-downstream-no-translation-desktop_translations.desktop.h $DESKTOP_NAME-downstream-translated-raw.desktop +fi + +# Generate output in the OTHER directory +cd .. +RPM_OTHER_DIR=${RPM_BUILD_DIR%/BUILD*}/OTHER +if test -f $RPM_OTHER_DIR/update-desktop-files.tar.gz ; then + X=r +else + X=c +fi +cd .. +tar ${X}f $RPM_OTHER_DIR/update-desktop-files.tar.gz update-desktop-files + +EOF=EOF +cat <$DESKTOP_NAME.desktop.in +patch <$DESKTOP_NAME-downstream-in-translated.diff + +Source{number}: $DESKTOP_NAME.desktop.in +or +Source{number}: $DESKTOP_NAME.desktop + +cp %{SOURCE{NUMBER}} . + +%translate_suse_desktop $DESKTOP_NAME.desktop + +install -D -m 0644 $DESKTOP_NAME.desktop %{buildroot}${DESKTOP_PATH#$RPM_BUILD_ROOT}$DESKTOP_NAME.desktop + +osc add $DESKTOP_NAME.desktop.in +osc rm $DESKTOP_NAME.desktop + +if ! diff $DESKTOP_NAME.desktop %{SOURCE{number}} ; then +cat < + +- Generate files that allow easy upstreaming. (boo#1158957) +- Embed SUSE translations to the desktop file + (add suse_update_desktop_file_process_translations.py). + ------------------------------------------------------------------- Tue Dec 6 17:11:05 UTC 2022 - Dominique Leuenberger diff --git a/update-desktop-files.spec b/update-desktop-files.spec index 40d0b6e..ae623a6 100644 --- a/update-desktop-files.spec +++ b/update-desktop-files.spec @@ -1,7 +1,7 @@ # # spec file for package update-desktop-files # -# Copyright (c) 2022 SUSE LLC +# Copyright (c) 2024 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -27,10 +27,14 @@ Source: suse_update_desktop_file.sh Source1: map-desktop-category.sh Source2: macro Source4: brp-trim-translations.sh +Source5: suse_update_desktop_file_process_translations.py # This is not true technically, but we do that to make the rpm macros from # desktop-file-utils available to most packages that ship a .desktop file # (since they already have a update-desktop-files BuildRequires). Requires: desktop-file-utils +Requires: desktop-translations-devel +Requires: gettext-tools +Requires: intltool BuildArch: noarch %description @@ -72,7 +76,7 @@ sed -e '/awk/d' < %SOURCE4 > brp-extract-translations %install mkdir -p $RPM_BUILD_ROOT%_rpmconfigdir -install -m0755 %SOURCE0 %SOURCE1 $RPM_BUILD_ROOT%_rpmconfigdir +install -m0755 %SOURCE0 %SOURCE1 %SOURCE5 $RPM_BUILD_ROOT%_rpmconfigdir install -m0644 -D %SOURCE2 $RPM_BUILD_ROOT%_rpmmacrodir/macros.%name install -m0755 -D %SOURCE4 $RPM_BUILD_ROOT/usr/lib/rpm/brp-suse.d/brp-70-trim-translations install -m0755 -D brp-extract-translations $RPM_BUILD_ROOT/usr/lib/rpm/brp-suse.d/brp-70-extract-translations