137 lines
4.9 KiB
Diff
137 lines
4.9 KiB
Diff
Index: glib-2.17.3/glib/gkeyfile.c
|
|
===================================================================
|
|
--- glib-2.17.3.orig/glib/gkeyfile.c
|
|
+++ glib-2.17.3/glib/gkeyfile.c
|
|
@@ -83,6 +83,7 @@ struct _GKeyFile
|
|
GKeyFileFlags flags;
|
|
|
|
gchar **locales;
|
|
+ gchar *gettext_domain;
|
|
};
|
|
|
|
typedef struct _GKeyFileKeyValuePair GKeyFileKeyValuePair;
|
|
@@ -209,6 +210,7 @@ g_key_file_init (GKeyFile *key_file)
|
|
key_file->list_separator = ';';
|
|
key_file->flags = 0;
|
|
key_file->locales = g_strdupv ((gchar **)g_get_language_names ());
|
|
+ key_file->gettext_domain = NULL;
|
|
}
|
|
|
|
static void
|
|
@@ -228,6 +230,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)
|
|
{
|
|
@@ -448,6 +456,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;
|
|
}
|
|
|
|
@@ -554,6 +567,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;
|
|
}
|
|
|
|
@@ -1653,6 +1671,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);
|
|
@@ -1682,7 +1702,24 @@ g_key_file_get_locale_string (GKeyFile
|
|
languages = (gchar **) g_get_language_names ();
|
|
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]);
|
|
@@ -1697,6 +1734,31 @@ g_key_file_get_locale_string (GKeyFile
|
|
|
|
g_free (translated_value);
|
|
translated_value = NULL;
|
|
+
|
|
+ if (try_gettext && strcmp (msg_locale, languages[i]) == 0)
|
|
+ {
|
|
+ gchar *orig_value = g_key_file_get_string (key_file, group_name, key, NULL);
|
|
+
|
|
+ if (orig_value)
|
|
+ {
|
|
+ gboolean has_gettext;
|
|
+
|
|
+ translated_value = dgettext (key_file->gettext_domain, orig_value);
|
|
+ has_gettext = translated_value != orig_value;
|
|
+ g_free (orig_value);
|
|
+
|
|
+ if (has_gettext)
|
|
+ {
|
|
+ if (bind_textdomain_codeset (key_file->gettext_domain, NULL))
|
|
+ translated_value = g_strdup (translated_value);
|
|
+ else
|
|
+ translated_value = g_locale_to_utf8 (translated_value, -1, NULL, NULL, NULL);
|
|
+ break;
|
|
+ }
|
|
+ else
|
|
+ translated_value = NULL;
|
|
+ }
|
|
+ }
|
|
}
|
|
|
|
/* Fallback to untranslated key
|
|
Index: glib-2.17.3/glib/gkeyfile.h
|
|
===================================================================
|
|
--- glib-2.17.3.orig/glib/gkeyfile.h
|
|
+++ glib-2.17.3/glib/gkeyfile.h
|
|
@@ -240,6 +240,7 @@ gboolean g_key_file_remove_group
|
|
#define G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY "StartupNotify"
|
|
#define G_KEY_FILE_DESKTOP_KEY_STARTUP_WM_CLASS "StartupWMClass"
|
|
#define G_KEY_FILE_DESKTOP_KEY_URL "URL"
|
|
+#define G_KEY_FILE_DESKTOP_KEY_GETTEXT_DOMAIN "X-SUSE-Gettext-Domain"
|
|
|
|
#define G_KEY_FILE_DESKTOP_TYPE_APPLICATION "Application"
|
|
#define G_KEY_FILE_DESKTOP_TYPE_LINK "Link"
|