diff --git a/libappstream-glib.spec b/libappstream-glib.spec index 8709443..25a275c 100644 --- a/libappstream-glib.spec +++ b/libappstream-glib.spec @@ -6,11 +6,14 @@ Summary: Library for AppStream metadata Name: libappstream-glib Version: 0.7.16 -Release: 1%{?dist} +Release: 2%{?dist} License: LGPLv2+ URL: http://people.freedesktop.org/~hughsient/appstream-glib/ Source0: http://people.freedesktop.org/~hughsient/appstream-glib/releases/appstream-glib-%{version}.tar.xz +# Backported from upstream +Patch0: qt-translations-subdir.patch + BuildRequires: glib2-devel >= %{glib2_version} BuildRequires: docbook-utils BuildRequires: gtk-doc @@ -26,6 +29,7 @@ BuildRequires: libstemmer-devel BuildRequires: json-glib-devel >= %{json_glib_version} BuildRequires: meson BuildRequires: rpm-devel +BuildRequires: git-core # for the builder component BuildRequires: fontconfig-devel @@ -75,7 +79,7 @@ This library and command line tool is used for building AppStream metadata from a directory of packages. %prep -%autosetup -p1 -n appstream-glib-%{version} +%autosetup -p1 -Sgit -n appstream-glib-%{version} %build %meson \ @@ -130,6 +134,9 @@ from a directory of packages. %{_mandir}/man1/appstream-builder.1.gz %changelog +* Thu Nov 14 2019 Kalev Lember - 0.7.16-2 +- Backport a patch to fix parsing Qt translations in subdirectories + * Mon Sep 30 2019 Richard Hughes 0.7.16-1 - Update to 0.7.15 - Add UPL short name to SPDX conversion diff --git a/qt-translations-subdir.patch b/qt-translations-subdir.patch new file mode 100644 index 0000000..3b24883 --- /dev/null +++ b/qt-translations-subdir.patch @@ -0,0 +1,221 @@ +From cea76b901569f8b0c384abe325db37fe445fd341 Mon Sep 17 00:00:00 2001 +From: Kalev Lember +Date: Thu, 14 Nov 2019 14:26:46 +0100 +Subject: [PATCH 1/3] trivial: Move a check earlier so that we exit the correct + loop + +--- + libappstream-glib/as-app-builder.c | 10 +++++----- + 1 file changed, 5 insertions(+), 5 deletions(-) + +diff --git a/libappstream-glib/as-app-builder.c b/libappstream-glib/as-app-builder.c +index 16185ed..6ad0d9a 100644 +--- a/libappstream-glib/as-app-builder.c ++++ b/libappstream-glib/as-app-builder.c +@@ -344,6 +344,11 @@ as_app_builder_search_translations_qt (AsAppBuilderContext *ctx, + /* FIXME: this path probably has to be specified as an attribute + * in the tag from the AppData file */ + t = g_ptr_array_index (ctx->translations, i); ++ if (as_translation_get_kind (t) != AS_TRANSLATION_KIND_QT && ++ as_translation_get_kind (t) != AS_TRANSLATION_KIND_UNKNOWN) ++ continue; ++ if (as_translation_get_id (t) == NULL) ++ continue; + install_dir = as_translation_get_id (t); + path = g_build_filename (prefix, + "share", +@@ -360,11 +365,6 @@ as_app_builder_search_translations_qt (AsAppBuilderContext *ctx, + while ((filename = g_dir_read_name (dir)) != NULL) { + g_autofree gchar *fn = NULL; + g_autofree gchar *locale = NULL; +- if (as_translation_get_kind (t) != AS_TRANSLATION_KIND_QT && +- as_translation_get_kind (t) != AS_TRANSLATION_KIND_UNKNOWN) +- continue; +- if (as_translation_get_id (t) == NULL) +- continue; + if (!g_str_has_prefix (filename, as_translation_get_id (t))) + continue; + locale = g_strdup (filename + strlen (as_translation_get_id (t)) + 1); +-- +2.23.0 + + +From e304d6a8b0233c6b805cb68f53bd73259733dac9 Mon Sep 17 00:00:00 2001 +From: Kalev Lember +Date: Thu, 14 Nov 2019 14:27:34 +0100 +Subject: [PATCH 2/3] Support ${id}/${locale}.qm in addition to + ${id}_${locale}.qm + +--- + libappstream-glib/as-app-builder.c | 41 ++++++++++++++++++++++++++++-- + 1 file changed, 39 insertions(+), 2 deletions(-) + +diff --git a/libappstream-glib/as-app-builder.c b/libappstream-glib/as-app-builder.c +index 6ad0d9a..bc712bd 100644 +--- a/libappstream-glib/as-app-builder.c ++++ b/libappstream-glib/as-app-builder.c +@@ -1,6 +1,7 @@ + /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2015 Richard Hughes ++ * Copyright (C) 2019 Kalev Lember + * + * SPDX-License-Identifier: LGPL-2.1+ + */ +@@ -336,6 +337,7 @@ as_app_builder_search_translations_qt (AsAppBuilderContext *ctx, + /* search for each translation ID */ + for (i = 0; i < ctx->translations->len; i++) { + AsTranslation *t; ++ const gchar *dirname; + const gchar *filename; + const gchar *install_dir; + g_autofree gchar *path = NULL; +@@ -361,18 +363,53 @@ as_app_builder_search_translations_qt (AsAppBuilderContext *ctx, + if (dir == NULL) + return FALSE; + +- /* the format is ${prefix}/share/${install_dir}/translations/${id}_${locale}.qm */ ++ /* look for ${prefix}/share/${install_dir}/translations/${id}_${locale}.qm */ + while ((filename = g_dir_read_name (dir)) != NULL) { + g_autofree gchar *fn = NULL; + g_autofree gchar *locale = NULL; + if (!g_str_has_prefix (filename, as_translation_get_id (t))) + continue; ++ if (!g_str_has_suffix (filename, ".qm")) ++ continue; ++ fn = g_build_filename (path, filename, NULL); ++ if (!g_file_test (fn, G_FILE_TEST_IS_REGULAR)) ++ continue; + locale = g_strdup (filename + strlen (as_translation_get_id (t)) + 1); + g_strdelimit (locale, ".", '\0'); +- fn = g_build_filename (path, filename, NULL); + if (!as_app_builder_parse_file_qt (ctx, locale, fn, error)) + return FALSE; + } ++ ++ g_dir_rewind (dir); ++ ++ /* look for ${prefix}/share/${install_dir}/translations/${id}/${locale}.qm */ ++ while ((dirname = g_dir_read_name (dir)) != NULL) { ++ g_autofree gchar *path_subdir = NULL; ++ g_autoptr(GDir) subdir = NULL; ++ ++ if (!g_str_equal (dirname, as_translation_get_id (t))) ++ continue; ++ path_subdir = g_build_filename (path, dirname, NULL); ++ if (!g_file_test (path_subdir, G_FILE_TEST_IS_DIR)) ++ continue; ++ subdir = g_dir_open (path_subdir, 0, error); ++ if (subdir == NULL) ++ return FALSE; ++ ++ while ((filename = g_dir_read_name (subdir)) != NULL) { ++ g_autofree gchar *fn = NULL; ++ g_autofree gchar *locale = NULL; ++ if (!g_str_has_suffix (filename, ".qm")) ++ continue; ++ fn = g_build_filename (path_subdir, filename, NULL); ++ if (!g_file_test (fn, G_FILE_TEST_IS_REGULAR)) ++ continue; ++ locale = g_strdup (filename); ++ g_strdelimit (locale, ".", '\0'); ++ if (!as_app_builder_parse_file_qt (ctx, locale, fn, error)) ++ return FALSE; ++ } ++ } + } + + return TRUE; +-- +2.23.0 + + +From 2e13dcc11de8c4da5822f51fd32f08917f012d09 Mon Sep 17 00:00:00 2001 +From: Kalev Lember +Date: Thu, 14 Nov 2019 14:53:30 +0100 +Subject: [PATCH 3/3] trivial: Add a new self test for ${id}/${locale}.qm + translations + +--- + .../share/kdeapp2/translations/kdeapp2/fr.qm | Bin 0 -> 112 bytes + libappstream-glib/as-self-test.c | 38 ++++++++++++++++++ + 2 files changed, 38 insertions(+) + create mode 100644 data/tests/usr/share/kdeapp2/translations/kdeapp2/fr.qm + +diff --git a/data/tests/usr/share/kdeapp2/translations/kdeapp2/fr.qm b/data/tests/usr/share/kdeapp2/translations/kdeapp2/fr.qm +new file mode 100644 +index 0000000000000000000000000000000000000000..3c6397e22d17fde3e441b4c4bc8ed0044290f115 +GIT binary patch +literal 112 +zcmcE7ks@*G{hX<16=n7(EZlq7iGhKEgHdFS2#{vT1Y&n)AfdqE#E{RB$B+diOBsrQ +z{2Ycb=;6qVrB#Y9po4; + +literal 0 +HcmV?d00001 + +diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c +index 7100f69..eb4cd10 100644 +--- a/libappstream-glib/as-self-test.c ++++ b/libappstream-glib/as-self-test.c +@@ -1,6 +1,7 @@ + /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2014-2018 Richard Hughes ++ * Copyright (C) 2019 Kalev Lember + * + * SPDX-License-Identifier: LGPL-2.1+ + */ +@@ -437,6 +438,42 @@ as_test_app_builder_qt_func (void) + g_assert_cmpint (g_list_length (list), ==, 1); + } + ++static void ++as_test_app_builder_qt_subdir_func (void) ++{ ++ GError *error = NULL; ++ gboolean ret; ++ guint i; ++ g_autofree gchar *fn = NULL; ++ g_autoptr(AsApp) app = NULL; ++ g_autoptr(GList) list = NULL; ++ const gchar *gettext_domains[] = { "kdeapp2", "notgoingtoexist", NULL }; ++ ++ app = as_app_new (); ++ fn = as_test_get_filename ("usr"); ++ g_assert (fn != NULL); ++ for (i = 0; gettext_domains[i] != NULL; i++) { ++ g_autoptr(AsTranslation) translation = NULL; ++ translation = as_translation_new (); ++ as_translation_set_kind (translation, AS_TRANSLATION_KIND_QT); ++ as_translation_set_id (translation, gettext_domains[i]); ++ as_app_add_translation (app, translation); ++ } ++ ret = as_app_builder_search_translations (app, fn, 25, ++ AS_APP_BUILDER_FLAG_NONE, ++ NULL, &error); ++ g_assert_no_error (error); ++ g_assert (ret); ++ ++ /* check langs */ ++ g_assert_cmpint (as_app_get_language (app, "fr"), ==, 100); ++ g_assert_cmpint (as_app_get_language (app, "en_GB"), ==, -1); ++ ++ /* check size */ ++ list = as_app_get_languages (app); ++ g_assert_cmpint (g_list_length (list), ==, 1); ++} ++ + static void + as_test_tag_func (void) + { +@@ -5693,6 +5730,7 @@ main (int argc, char **argv) + g_test_add_func ("/AppStream/app{builder:gettext}", as_test_app_builder_gettext_func); + g_test_add_func ("/AppStream/app{builder:gettext-nodomain}", as_test_app_builder_gettext_nodomain_func); + g_test_add_func ("/AppStream/app{builder:qt}", as_test_app_builder_qt_func); ++ g_test_add_func ("/AppStream/app{builder:qt-subdir}", as_test_app_builder_qt_subdir_func); + g_test_add_func ("/AppStream/app{translated}", as_test_app_translated_func); + g_test_add_func ("/AppStream/app{validate-style}", as_test_app_validate_style_func); + g_test_add_func ("/AppStream/app{validate-appdata-good}", as_test_app_validate_appdata_good_func); +-- +2.23.0 +