From 65db7c614c7a3678dbfbe431c61510a23904604a Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Sun, 10 Mar 2019 00:21:19 +0100 Subject: Adjust load order of get_filename() function It now always prefers - files in the users profile over files in the share/inkscape folder - localized files over unlocalized files (per folder) In conclusion: USER (localized) > USER > SYSTEM (localized) > SYSTEM This always allows users to override files shipped with Inkscape by putting a respective file in their profile directory. First part of a fix for https://gitlab.com/inkscape/inkscape/issues/103 Avoids regressing https://bugs.launchpad.net/inkscape/+bug/503712 --- src/io/resource.cpp | 62 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/io/resource.cpp b/src/io/resource.cpp index 8c3ab65bf..ff934b2c5 100644 --- a/src/io/resource.cpp +++ b/src/io/resource.cpp @@ -150,47 +150,55 @@ Glib::ustring get_filename(Type type, char const *filename, bool localized) { Glib::ustring result; + char *user_filename = nullptr; + char *sys_filename = nullptr; + char *user_filename_localized = nullptr; + char *sys_filename_localized = nullptr; + // TRANSLATORS: 'en' is an ISO 639-1 language code. // Replace with language code for your language, i.e. the name of your .po file - if (localized && strcmp(_("en"), "en")) { + localized = localized && strcmp(_("en"), "en"); + + if (localized) { Glib::ustring localized_filename = filename; localized_filename.insert(localized_filename.rfind('.'), "."); localized_filename.insert(localized_filename.rfind('.'), _("en")); - char *user_locale = _get_path(USER, type, localized_filename.c_str()); - char *sys_locale = _get_path(SYSTEM, type, localized_filename.c_str()); - - if (file_test(user_locale, G_FILE_TEST_EXISTS)) { - result = Glib::ustring(user_locale); - } else if(file_test(sys_locale, G_FILE_TEST_EXISTS)) { - result = Glib::ustring(sys_locale); - } - g_free(user_locale); - g_free(sys_locale); - - if(!result.empty()) { - g_info("Using translated resource file: %s", result.c_str()); - return result; - } + user_filename_localized = _get_path(USER, type, localized_filename.c_str()); + sys_filename_localized = _get_path(SYSTEM, type, localized_filename.c_str()); } - - char *user_filename = _get_path(USER, type, filename); - char *sys_filename = _get_path(SYSTEM, type, filename); - - if (file_test(user_filename, G_FILE_TEST_EXISTS)) { + user_filename = _get_path(USER, type, filename); + sys_filename = _get_path(SYSTEM, type, filename); + + // impose the following load order: + // USER (localized) > USER > SYSTEM (localized) > SYSTEM + if (localized && file_test(user_filename_localized, G_FILE_TEST_EXISTS)) { + result = Glib::ustring(user_filename_localized); + g_info("Found localized version of resource file '%s' in profile directory:\n\t%s", filename, result.c_str()); + } else if (file_test(user_filename, G_FILE_TEST_EXISTS)) { result = Glib::ustring(user_filename); - } else if(file_test(sys_filename, G_FILE_TEST_EXISTS)) { + g_info("Found resource file '%s' in profile directory:\n\t%s", filename, result.c_str()); + } else if (localized && file_test(sys_filename_localized, G_FILE_TEST_EXISTS)) { + result = Glib::ustring(sys_filename_localized); + g_info("Found localized version of resource file '%s' in system directory:\n\t%s", filename, result.c_str()); + } else if (file_test(sys_filename, G_FILE_TEST_EXISTS)) { result = Glib::ustring(sys_filename); + g_info("Found resource file '%s' in system directory:\n\t%s", filename, result.c_str()); } else { - g_warning("Failed to load resource: %s from %s or %s", filename, user_filename, sys_filename); - } - - if(!result.empty()) { - g_info("Using resource file: %s", result.c_str()); + if (localized) { + g_warning("Failed to find resource file '%s'. Looked in:\n\t%s\n\t%s\n\t%s\n\t%s", + filename, user_filename_localized, user_filename, sys_filename_localized, sys_filename); + } else { + g_warning("Failed to find resource file '%s'. Looked in:\n\t%s\n\t%s", + filename, user_filename, sys_filename); + } } g_free(user_filename); g_free(sys_filename); + g_free(user_filename_localized); + g_free(sys_filename_localized); + return result; } -- cgit v1.2.3