glib2/glib2-bgo569829-gettext-gkeyfile.patch
Dominique Leuenberger cb79a1ee9d Accepting request 1072740 from GNOME:Next
- Update to version 2.76.0:
  + Fix several regressions in handling `GFileInfo` attributes
  + Bugs fixed:
    - ETAG_VALUE not set in GFileInfo when requested
    - File attributes are not set when their value is FALSE/NULL
    - gfile: Fix file size detection when copying on btrfs
    - glocalfileinfo:
      . Mark the lost+found dir as hidden again
      . Ensure that is-backup is always set
  + Updated translations.
- Rebase patches with quilt.
- Update to version 2.75.4:
  + Emit a critical warning when acquiring the notification queue
    during GObject finalization. A type's `finalize()`
    implementation should not call public API that emits property
    notifications.
  + Updated translations.
- Rebase glib2-suppress-schema-deprecated-path-warning.patch with
  quilt.
- Fix license files in packages: COPYING in the source tree is
  a symlink to LICENSES/LGPL-2.1-or-later.txt, but rpm's %license
  macro copies the symlink, not the target. Explicitly package
  LICENSES/LGPL-2.1-or-later.txt in this case (boo#1208497).
- Update to version 2.75.3:
  + Drop the implementation of GSlice, and make the API use the
    system `malloc()` internally.
  + Use a thread-spawning thread to keep thread scheduler settings
    consistent; fixes GThreadPool critical warnings due to failing
    to set scheduler settings in some situations.
  + GIR annotation improvements for multiple APIs.
  + Optimise printing of nested maybes in `g_variant_print()`.
  + Use `tap` test protocol within GLib, and support TAP 13/14.
  + Fix a regression in glib-compile-schemas 2.75.2 causing schemas
    and override files to be sorted incorrectly.
  + Support per-desktop overrides in `GSettingsAction`.
  + Various optimisations to `GString`.
  + Reduce allocations in message printing functions if there’s
    nothing to format.
  + Add inline version of `g_strdup()`, allowing the compiler to do
    `NULL` folding and constant folding on `strlen()` calls.
  + Add a `GPathBuf` API for building and manipulating file paths.
  + Add `g_string_free_and_steal()` and use it to warn on unused
    results from`g_string_free (_, FALSE)`.
  + Add `g_free_sized()` and `g_aligned_free_sized()` to mirror the
    upcoming `free_sized()` function in C23; use these if porting
    away from `g_slice_free()`.
  + Fix underspecified dependencies on generated headers in
    `meson.build`, which should reduce spurious build failures.
  + Updated translations.
- Update to version 2.75.2:
  + Add `g_ptr_array_sort_values()` and
    `g_ptr_array_sort_values_with_data()` APIs.
  + Some fixes for activation of UWP apps on Windows.
  + Support Markdown output from `gdbus-codegen`.
- Changes from version 2.75.1:
  + Add new `GFileInfo` properties for large thumbnails.
  + Fix missing input validation in `GDBusMenuModel`.
  + Change default `g_desktop_app_info_search()` algorithm to
    include substring matches.
  + Various GVariant security fixes when handling untrusted data.
  + Add support for XDG Activation protocol in `GAppLaunchContext`.
  + Return `application/x-zerosize` rather than `text/plain` as
    content type for empty files.
  + Deprecate `-Druntime_libdir` configure option because it was
    unused.
  + Check for snap plugs when accessing portals.
  + Add `GArray` and `GPtrArray` constructors to take or copy C
    arrays.
  + Add `GHashTable` methods to get and steal hash table keys and
    values as `GPtrArray`s.
  + Change the default D-Bus system bus socket address from
    `/var/run/dbus/system_bus_socket` to
    `/run/dbus/system_bus_socket`, in line with changes in
    dbus.git.
- Drop glib2-dbus-socket-path.patch: fixed upstream.

OBS-URL: https://build.opensuse.org/request/show/1072740
OBS-URL: https://build.opensuse.org/package/show/GNOME:Factory/glib2?expand=0&rev=507
2023-03-20 12:47:33 +00:00

143 lines
4.9 KiB
Diff

Index: glib-2.75.4/glib/gkeyfile.c
===================================================================
--- glib-2.75.4.orig/glib/gkeyfile.c
+++ glib-2.75.4/glib/gkeyfile.c
@@ -519,6 +519,7 @@ struct _GKeyFile
gboolean checked_locales; /* TRUE if @locales has been initialised */
gchar **locales; /* (nullable) */
+ gchar *gettext_domain;
gint ref_count; /* (atomic) */
};
@@ -645,6 +646,7 @@ g_key_file_init (GKeyFile *key_file)
key_file->parse_buffer = NULL;
key_file->list_separator = ';';
key_file->flags = 0;
+ key_file->gettext_domain = NULL;
}
static void
@@ -665,6 +667,12 @@ g_key_file_clear (GKeyFile *key_file)
key_file->parse_buffer = NULL;
}
+ if (key_file->gettext_domain)
+ {
+ g_free (key_file->gettext_domain);
+ key_file->gettext_domain = NULL;
+ }
+
tmp = key_file->groups;
while (tmp != NULL)
{
@@ -885,6 +893,11 @@ g_key_file_load_from_fd (GKeyFile
return FALSE;
}
+ key_file->gettext_domain = g_key_file_get_string (key_file,
+ G_KEY_FILE_DESKTOP_GROUP,
+ G_KEY_FILE_DESKTOP_KEY_GETTEXT_DOMAIN,
+ NULL);
+
return TRUE;
}
@@ -997,6 +1010,11 @@ g_key_file_load_from_data (GKeyFile
return FALSE;
}
+ key_file->gettext_domain = g_key_file_get_string (key_file,
+ G_KEY_FILE_DESKTOP_GROUP,
+ G_KEY_FILE_DESKTOP_KEY_GETTEXT_DOMAIN,
+ NULL);
+
return TRUE;
}
@@ -2246,6 +2264,8 @@ g_key_file_get_locale_string (GKeyFile
GError *key_file_error;
gchar **languages;
gboolean free_languages = FALSE;
+ gboolean try_gettext = FALSE;
+ const gchar *msg_locale;
gint i;
g_return_val_if_fail (key_file != NULL, NULL);
@@ -2267,6 +2287,23 @@ g_key_file_get_locale_string (GKeyFile
free_languages = FALSE;
}
+ /* we're only interested in gettext translation if we don't have a
+ * translation in the .desktop file itself and if the key is one of the keys
+ * we know we want to translate: Name, GenericName, Comment. Blindly doing
+ * this for all keys can give strange result for the icons, since the Icon is
+ * a locale string in the spec, eg. We also only get translation in the mo
+ * file if the requested locale is the LC_MESSAGES one. Ideally, we should do
+ * more and change LC_MESSAGES to use the requested locale, but there's no
+ * guarantee it's installed on the system and it might have some
+ * side-effects. Since this is a corner case, let's ignore it. */
+
+ msg_locale = setlocale (LC_MESSAGES, NULL);
+ try_gettext = msg_locale && key_file->gettext_domain &&
+ strcmp (group_name, G_KEY_FILE_DESKTOP_GROUP) == 0 &&
+ (strcmp (key, G_KEY_FILE_DESKTOP_KEY_NAME) == 0 ||
+ strcmp (key, G_KEY_FILE_DESKTOP_KEY_GENERIC_NAME) == 0 ||
+ strcmp (key, G_KEY_FILE_DESKTOP_KEY_COMMENT) == 0);
+
for (i = 0; languages[i]; i++)
{
candidate_key = g_strdup_printf ("%s[%s]", key, languages[i]);
@@ -2280,6 +2317,39 @@ g_key_file_get_locale_string (GKeyFile
break;
}
+ /* Fallback to gettext */
+ if (try_gettext && !translated_value)
+ {
+ gchar *orig_value = g_key_file_get_string (key_file, group_name, key, NULL);
+
+ if (orig_value)
+ {
+ gboolean codeset_set;
+ const gchar *translated;
+ gboolean has_gettext;
+
+ codeset_set = bind_textdomain_codeset (key_file->gettext_domain, "UTF-8") != NULL;
+ translated = NULL;
+
+ translated = g_dgettext (key_file->gettext_domain,
+ orig_value);
+ has_gettext = translated != orig_value;
+
+ g_free (orig_value);
+
+ if (has_gettext)
+ {
+ if (codeset_set)
+ translated_value = g_strdup (translated);
+ else
+ translated_value = g_locale_to_utf8 (translated,
+ -1, NULL, NULL, NULL);
+ }
+ else
+ translated_value = NULL;
+ }
+ }
+
/* Fallback to untranslated key
*/
if (!translated_value)
Index: glib-2.75.4/glib/gkeyfile.h
===================================================================
--- glib-2.75.4.orig/glib/gkeyfile.h
+++ glib-2.75.4/glib/gkeyfile.h
@@ -322,6 +322,7 @@ gboolean g_key_file_remove_group
#define G_KEY_FILE_DESKTOP_KEY_URL "URL"
#define G_KEY_FILE_DESKTOP_KEY_DBUS_ACTIVATABLE "DBusActivatable"
#define G_KEY_FILE_DESKTOP_KEY_ACTIONS "Actions"
+#define G_KEY_FILE_DESKTOP_KEY_GETTEXT_DOMAIN "X-GNOME-Gettext-Domain"
#define G_KEY_FILE_DESKTOP_TYPE_APPLICATION "Application"
#define G_KEY_FILE_DESKTOP_TYPE_LINK "Link"