diff --git a/brp-trim-desktop.sh b/brp-trim-desktop.sh
deleted file mode 100644
index e561492..0000000
--- a/brp-trim-desktop.sh
+++ /dev/null
@@ -1,56 +0,0 @@
-#! /bin/sh
-
-# macro: suse_update_desktop_file
-#
-# Used to add easily a category to .desktop files according to XDG
-# standard.
-#
-
-#
-# find file
-#
-BASEDIR=`dirname $RPM_SOURCE_DIR`/OTHER
-
-if ! test -f /.buildenv; then
- # this looks fishy, skip it
- echo "WARNING: I better not trim without a /.buildenv around"
- exit 0
-fi
-
-if ! test -w $BASEDIR; then
- echo "WARNING: Can't write to $BASEDIR, skipping"
- exit 0
-fi
-
-find /$RPM_BUILD_ROOT/opt/kde3/share/applications/kde/ \
- /$RPM_BUILD_ROOT/opt/kde3/share/applnk/ \
- /$RPM_BUILD_ROOT/usr/share/xsessions/ \
- /$RPM_BUILD_ROOT/usr/share/applications/ \
- /$RPM_BUILD_ROOT/usr/share/mimelnk/ \
- /$RPM_BUILD_ROOT/usr/share/gnome/apps/ \
- /$RPM_BUILD_ROOT/usr/share/autostart/ \
- /$RPM_BUILD_ROOT/etc/xdg/autostart/ \
- /$RPM_BUILD_ROOT/usr/share/wallpapers \
- /$RPM_BUILD_ROOT/usr/share/autoinstall/ \
- -type f \( -name '*.desktop' -o -name .directory \) 2>/dev/null | while read -r FILE; do
-
- if grep -q ^X-SuSE-translate= "$FILE"; then
- echo "DEBUG: $FILE contains X-SuSE-translate - skipping" >&2
- continue
- fi
-
- # save for backup
- NFILE="${FILE#$RPM_BUILD_ROOT}"
- echo "<<$NFILE>>" >> $BASEDIR/$RPM_PACKAGE_NAME.desktopfiles
- cat "$FILE" >> $BASEDIR/$RPM_PACKAGE_NAME.desktopfiles
- # make sure we end with a newline
- echo >> $BASEDIR/$RPM_PACKAGE_NAME.desktopfiles
- echo "trimmed output to $BASEDIR/$RPM_PACKAGE_NAME.desktopfiles"
-
- #
- # Trim translations (desktops will use gettext to find them)
- #
- sed -e '/^\(Name\[\|GenericName\[\|Comment\[\)/d' -e '/^\[Desktop Entry\]/a \
-X-SuSE-translate=true' "$FILE" > "${FILE}_" && mv "${FILE}_" "$FILE"
-done
-
diff --git a/brp-trim-translations.sh b/brp-trim-translations.sh
new file mode 100644
index 0000000..888f485
--- /dev/null
+++ b/brp-trim-translations.sh
@@ -0,0 +1,129 @@
+#!/bin/bash
+# This script goes through all polkit actions, appstream metadata and mimeinfo xml data
+# and copies the .xml files into a .tar.xz for each kind. Then the xml:lang values are
+# stripped out.
+
+BASEDIR=`dirname $RPM_SOURCE_DIR`/OTHER
+
+if ! test -f /.buildenv; then
+ # this looks fishy, skip it
+ echo "WARNING: I better not trim without a /.buildenv around"
+ exit 0
+fi
+
+if ! test -w $BASEDIR; then
+ echo "WARNING: Can't write to $BASEDIR, skipping"
+ exit 0
+fi
+
+strip_xml_lang() {
+ type="$1"
+ file="$2"
+ notrim="$3"
+
+ if grep -q '^' "$file"; then
+ return
+ fi
+
+ nfile="${file#/$RPM_BUILD_ROOT}"
+ mkdir -p "$(dirname "${BASEDIR}/${type}/${nfile}")"
+ cp "${file}" "${BASEDIR}/${type}/${nfile}"
+
+ if [ -n "${notrim}" ]; then
+ return # Extraction only
+ fi
+
+ doctype=
+ if [ "$type" = "polkitactions" ]; then
+ doctype=''
+ elif [ "$type" = "appstream" ]; then
+ doctype=''
+ return # For now
+ elif [ "$type" = "mimetypes" ]; then
+ doctype=''
+ else
+ echo "Unknown type '${type}'!"
+ fi
+
+ xsltproc --novalid --nonet - "$file" > "${file}_" << EOF
+
+
+ $doctype
+
+
+
+
+
+
+
+
+
+
+
+EOF
+
+ if [ $? -ne 0 ]; then
+ echo "XSL processing failed - invalid XML?"
+ else
+ mv -- "${file}_" "${file}"
+ echo "trimmed output to ${BASEDIR}/${type}/${nfile}"
+ fi
+}
+
+strip_desktop_lang() {
+ type="$1"
+ file="$2"
+
+ if grep -q ^X-SuSE-translate= "${file}"; then
+ return
+ fi
+
+ nfile="${file#/$RPM_BUILD_ROOT}"
+ mkdir -p "$(dirname "${BASEDIR}/${type}/${nfile}")"
+ cp "${file}" "${BASEDIR}/${type}/${nfile}"
+ echo "trimmed output to ${BASEDIR}/${type}/${nfile}"
+ echo "trimmed output to $BASEDIR/$RPM_PACKAGE_NAME.desktopfiles"
+
+ sed -e '/^\(Name\[\|GenericName\[\|Comment\[\)/d' -e '/^\[Desktop Entry\]/a \
+X-SuSE-translate=true' "${file}" > "${file}_" && mv "${file}_" "${file}"
+}
+
+# Handle polkit actions
+find "/$RPM_BUILD_ROOT/usr/share/polkit-1/actions/" -type f -name '*.policy' | while read -r file; do
+ strip_xml_lang "polkitactions" "$file" "notrim"
+done
+
+# Handle mimetype info
+find "/$RPM_BUILD_ROOT/usr/share/mime/" -type f -name '*.xml' | while read -r file; do
+ strip_xml_lang "mimetypes" "$file" "notrim"
+done
+
+# Handle appstream metainfo
+find "/$RPM_BUILD_ROOT/usr/share/metainfo/" "/$RPM_BUILD_ROOT/usr/share/appdata/" -type f -name '*.xml' | while read -r file; do
+ strip_xml_lang "appstream" "$file" "notrim"
+done
+
+# Handle desktop files
+find "/$RPM_BUILD_ROOT/opt/kde3/share/applications/kde/" \
+ "/$RPM_BUILD_ROOT/opt/kde3/share/applnk/" \
+ "/$RPM_BUILD_ROOT/usr/share/xsessions/" \
+ "/$RPM_BUILD_ROOT/usr/share/applications/" \
+ "/$RPM_BUILD_ROOT/usr/share/mimelnk/" \
+ "/$RPM_BUILD_ROOT/usr/share/gnome/apps/" \
+ "/$RPM_BUILD_ROOT/usr/share/autostart/" \
+ "/$RPM_BUILD_ROOT/etc/xdg/autostart/" \
+ "/$RPM_BUILD_ROOT/usr/share/wallpapers/" \
+ "/$RPM_BUILD_ROOT/usr/share/autoinstall/" \
+ -type f \( -name '*.desktop' -o -name '.directory' \) 2>/dev/null | while read -r file; do
+ strip_desktop_lang "desktopfiles" "$file"
+done
+
+
+# Pack all files into tars
+for type in desktopfiles polkitactions mimetypes appstream; do
+ [ -d "${BASEDIR}/${type}" ] || continue
+ pushd "${BASEDIR}/${type}"
+ tar -cjf "${BASEDIR}/${RPM_PACKAGE_NAME}-${type}.tar.bz2" *
+ popd
+ rm -rf "${BASEDIR}/${type}"
+done
diff --git a/update-desktop-files.changes b/update-desktop-files.changes
index 9d03c30..2503756 100644
--- a/update-desktop-files.changes
+++ b/update-desktop-files.changes
@@ -1,3 +1,12 @@
+-------------------------------------------------------------------
+Tue Mar 14 16:13:15 UTC 2017 - fvogt@suse.com
+
+- Replace brp-trim-desktopfiles with brp-trim-translations:
+ * Supports various kinds of source files, not only desktop files
+ * Generates various tar archives instead of monolithic .desktopfiles file
+- Currently trims desktop file translations only, as polkit/mime/appstream
+ do not support gettext translations yet
+
-------------------------------------------------------------------
Sat Oct 24 05:03:02 UTC 2015 - coolo@suse.com
diff --git a/update-desktop-files.spec b/update-desktop-files.spec
index b484225..904c1b0 100644
--- a/update-desktop-files.spec
+++ b/update-desktop-files.spec
@@ -1,7 +1,7 @@
#
# spec file for package update-desktop-files
#
-# Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany.
+# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@@ -26,7 +26,7 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-build
Source: suse_update_desktop_file.sh
Source1: map-desktop-category.sh
Source2: macro
-Source4: brp-trim-desktop.sh
+Source4: brp-trim-translations.sh
# 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).
@@ -37,12 +37,16 @@ BuildArch: noarch
This package provides further translations and a shell script to update
desktop files. It is used by the %%suse_update_desktop_file rpm macro.
-%package -n brp-trim-desktopfiles
-Summary: Trim translations from .deskop files
+%package -n brp-trim-translations
+Summary: Trim translations from desktop files, polkit actions, mimetype descriptions and AppStream metainfo
Group: Development/Tools/Building
+Provides: brp-trim-desktop = %{version}
+Obsoletes: brp-trim-desktop < %{version}
+Requires: libxslt-tools
-%description -n brp-trim-desktopfiles
-Trim translations from all .deskop files found in build root
+%description -n brp-trim-translations
+Trim translations from all desktop files, polkit actions, mimetype descriptions
+and AppStream metainfo found in build root
%prep
%setup -q -n . -D -T 0
@@ -55,7 +59,7 @@ cd %name
mkdir -p $RPM_BUILD_ROOT%_rpmconfigdir
install -m0755 %SOURCE0 %SOURCE1 $RPM_BUILD_ROOT%_rpmconfigdir
install -m0644 -D %SOURCE2 $RPM_BUILD_ROOT/etc/rpm/macros.%name
-install -m0755 -D %SOURCE4 $RPM_BUILD_ROOT/usr/lib/rpm/brp-suse.d/brp-70-trim-desktopfiles
+install -m0755 -D %SOURCE4 $RPM_BUILD_ROOT/usr/lib/rpm/brp-suse.d/brp-70-trim-translations
%files
%defattr(-,root,root)
@@ -63,8 +67,9 @@ install -m0755 -D %SOURCE4 $RPM_BUILD_ROOT/usr/lib/rpm/brp-suse.d/brp-70-trim-de
%exclude %_rpmconfigdir/brp-suse.d
/etc/rpm/*
-%files -n brp-trim-desktopfiles
+%files -n brp-trim-translations
%defattr(-,root,root)
-%_rpmconfigdir/brp-suse.d
+%dir %_rpmconfigdir/brp-suse.d/
+%_rpmconfigdir/brp-suse.d/brp-70-trim-translations
%changelog