2023-03-20 13:47:33 +01:00
|
|
|
Index: glib-2.75.4/glib/gkeyfile.c
|
2009-02-06 17:03:35 +01:00
|
|
|
===================================================================
|
2023-03-20 13:47:33 +01:00
|
|
|
--- glib-2.75.4.orig/glib/gkeyfile.c
|
|
|
|
+++ glib-2.75.4/glib/gkeyfile.c
|
|
|
|
@@ -519,6 +519,7 @@ struct _GKeyFile
|
2009-02-06 17:03:35 +01:00
|
|
|
|
2022-03-21 09:34:56 +01:00
|
|
|
gboolean checked_locales; /* TRUE if @locales has been initialised */
|
|
|
|
gchar **locales; /* (nullable) */
|
2009-02-06 17:03:35 +01:00
|
|
|
+ gchar *gettext_domain;
|
|
|
|
|
2021-03-24 17:32:24 +01:00
|
|
|
gint ref_count; /* (atomic) */
|
2011-11-15 10:01:46 +01:00
|
|
|
};
|
2023-03-20 13:47:33 +01:00
|
|
|
@@ -645,6 +646,7 @@ g_key_file_init (GKeyFile *key_file)
|
2021-03-24 17:32:24 +01:00
|
|
|
key_file->parse_buffer = NULL;
|
2009-02-06 17:03:35 +01:00
|
|
|
key_file->list_separator = ';';
|
|
|
|
key_file->flags = 0;
|
|
|
|
+ key_file->gettext_domain = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2023-03-20 13:47:33 +01:00
|
|
|
@@ -665,6 +667,12 @@ g_key_file_clear (GKeyFile *key_file)
|
2009-02-06 17:03:35 +01:00
|
|
|
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)
|
|
|
|
{
|
2023-03-20 13:47:33 +01:00
|
|
|
@@ -885,6 +893,11 @@ g_key_file_load_from_fd (GKeyFile
|
2009-02-06 17:03:35 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-03-20 13:47:33 +01:00
|
|
|
@@ -997,6 +1010,11 @@ g_key_file_load_from_data (GKeyFile
|
2009-02-06 17:03:35 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-03-20 13:47:33 +01:00
|
|
|
@@ -2246,6 +2264,8 @@ g_key_file_get_locale_string (GKeyFile
|
2009-02-06 17:03:35 +01:00
|
|
|
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);
|
2023-03-20 13:47:33 +01:00
|
|
|
@@ -2267,6 +2287,23 @@ g_key_file_get_locale_string (GKeyFile
|
2009-02-06 17:03:35 +01:00
|
|
|
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]);
|
2023-03-20 13:47:33 +01:00
|
|
|
@@ -2280,6 +2317,39 @@ g_key_file_get_locale_string (GKeyFile
|
2021-11-05 09:44:42 +01:00
|
|
|
break;
|
2009-02-06 17:03:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
+ /* 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)
|
2023-03-20 13:47:33 +01:00
|
|
|
Index: glib-2.75.4/glib/gkeyfile.h
|
2009-02-06 17:03:35 +01:00
|
|
|
===================================================================
|
2023-03-20 13:47:33 +01:00
|
|
|
--- glib-2.75.4.orig/glib/gkeyfile.h
|
|
|
|
+++ glib-2.75.4/glib/gkeyfile.h
|
2022-10-31 09:00:38 +01:00
|
|
|
@@ -322,6 +322,7 @@ gboolean g_key_file_remove_group
|
2009-02-06 17:03:35 +01:00
|
|
|
#define G_KEY_FILE_DESKTOP_KEY_URL "URL"
|
2013-06-23 15:45:50 +02:00
|
|
|
#define G_KEY_FILE_DESKTOP_KEY_DBUS_ACTIVATABLE "DBusActivatable"
|
2013-07-31 20:54:03 +02:00
|
|
|
#define G_KEY_FILE_DESKTOP_KEY_ACTIONS "Actions"
|
2009-02-06 17:03:35 +01:00
|
|
|
+#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"
|