From e304d6a8b0233c6b805cb68f53bd73259733dac9 Mon Sep 17 00:00:00 2001 From: Kalev Lember Date: Thu, 14 Nov 2019 14:27:34 +0100 Subject: 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; -- cgit v1.2.1