File libxfce4util-xfce-rc-i18n.patch of Package libxfce4util
Index: libxfce4util-4.10.1/libxfce4util/xfce-rc-simple.c
===================================================================
--- libxfce4util-4.10.1.orig/libxfce4util/xfce-rc-simple.c
+++ libxfce4util-4.10.1/libxfce4util/xfce-rc-simple.c
@@ -54,6 +54,8 @@
/* name of the NULL group */
#define NULL_GROUP "[NULL]"
+/* default gettext domain for desktop file translations */
+#define _XFCE_RC_DESKTOP_FILE_DEFAULT_DOMAIN "desktop_translations"
typedef struct _Entry Entry;
typedef struct _LEntry LEntry;
@@ -103,6 +105,7 @@ struct _Entry
{
gchar *key;
gchar *value;
+ gchar *glvalue;
Entry *next;
Entry *prev;
LEntry *lfirst;
@@ -209,6 +212,7 @@ simple_add_entry (XfceRcSimple *simple,
entry = g_slice_new (Entry);
entry->key = g_string_chunk_insert (simple->string_chunk, key);
entry->value = g_string_chunk_insert (simple->string_chunk, value);
+ entry->glvalue = NULL;
entry->lfirst = NULL;
entry->llast = NULL;
@@ -554,6 +558,9 @@ simple_write (XfceRcSimple *simple, cons
static void
simple_entry_free (Entry *entry)
{
+ /* free any desktop file gettext translations */
+ g_free (entry->glvalue);
+
/* release all lentries */
g_slice_free_chain (LEntry, entry->lfirst, next);
@@ -639,9 +646,11 @@ _xfce_rc_simple_new (XfceRcSimple *share
+static gboolean default_domain_encoding_is_set = FALSE;
gboolean
_xfce_rc_simple_parse (XfceRcSimple *simple)
{
+ XfceRc *rc = XFCE_RC (simple);
gboolean readonly;
gchar line[LINE_MAX];
gchar *section;
@@ -653,7 +662,7 @@ _xfce_rc_simple_parse (XfceRcSimple *sim
_xfce_return_val_if_fail (simple != NULL, FALSE);
_xfce_return_val_if_fail (simple->filename != NULL, FALSE);
- readonly = xfce_rc_is_readonly (XFCE_RC (simple));
+ readonly = xfce_rc_is_readonly (rc);
fp = fopen (simple->filename, "r");
if (fp == NULL)
@@ -679,7 +688,7 @@ _xfce_rc_simple_parse (XfceRcSimple *sim
if (XFCE_RC (simple)->locale == NULL)
continue;
- if (xfce_locale_match (XFCE_RC (simple)->locale, locale) > XFCE_LOCALE_NO_MATCH
+ if (xfce_locale_match (rc->locale, locale) > XFCE_LOCALE_NO_MATCH
|| !readonly)
{
simple_add_entry (simple, key, value, locale);
@@ -688,6 +697,106 @@ _xfce_rc_simple_parse (XfceRcSimple *sim
fclose (fp);
+ /* if a locale is set and this is a desktop file, try to obtain translations
+ * for the Name, GenericName, and Comment entries via gettext
+ */
+ if (rc->locale)
+ {
+ Group *group;
+ Group *desktop_group = NULL;
+
+ /* check if this is a desktop file */
+ for (group = simple->gfirst; group != NULL; group = group->next)
+ {
+ if (str_is_equal (group->name, G_KEY_FILE_DESKTOP_GROUP))
+ {
+ desktop_group = group;
+ break;
+ }
+ }
+ if (desktop_group)
+ {
+ Entry *entry;
+ gchar *gettext_domain = NULL;
+ gchar *file_basename;
+ gboolean codeset_is_set = FALSE;
+
+ if (G_UNLIKELY(!default_domain_encoding_is_set))
+ {
+ default_domain_encoding_is_set =
+ (bind_textdomain_codeset (_XFCE_RC_DESKTOP_FILE_DEFAULT_DOMAIN,
+ "UTF-8") != NULL);
+ }
+
+ /* try to find a translation domain entry */
+ for (entry = desktop_group->efirst; entry != NULL;
+ entry = entry->next)
+ {
+ if (str_is_equal (entry->key,
+ G_KEY_FILE_DESKTOP_KEY_GETTEXT_DOMAIN))
+ {
+ gettext_domain = g_strdup (entry->value);
+ break;
+ }
+ }
+ /* fall back to to the default gettext domain for desktop entries */
+ if (!gettext_domain)
+ gettext_domain = g_strdup (_XFCE_RC_DESKTOP_FILE_DEFAULT_DOMAIN);
+
+ if (str_is_equal (gettext_domain, _XFCE_RC_DESKTOP_FILE_DEFAULT_DOMAIN))
+ codeset_is_set = default_domain_encoding_is_set;
+ else
+ codeset_is_set = (bind_textdomain_codeset (gettext_domain, "UTF-8") != NULL);
+
+ /* determine the basename of the desktop file needed for the gettext
+ * context
+ */
+ file_basename = g_strrstr (simple->filename, G_DIR_SEPARATOR_S);
+ if (G_LIKELY (file_basename != NULL))
+ file_basename++;
+ else
+ file_basename = simple->filename;
+
+ for (entry = desktop_group->efirst; entry != NULL;
+ entry = entry->next)
+ {
+ const gchar *context_translated_value = NULL;
+ const gchar *translated_value = NULL;
+ gchar *context_value;
+
+ /* only translate Name, GenericName, and Comment entries */
+ if (!str_is_equal (entry->key, G_KEY_FILE_DESKTOP_KEY_NAME) &&
+ !str_is_equal (entry->key, G_KEY_FILE_DESKTOP_KEY_GENERIC_NAME) &&
+ !str_is_equal (entry->key, G_KEY_FILE_DESKTOP_KEY_COMMENT))
+ continue;
+
+ /* try to get a translation with context */
+ context_value = g_strdup_printf ("%s(%s): %s", entry->key,
+ file_basename, entry->value);
+ context_translated_value = g_dgettext (gettext_domain, context_value);
+
+ /* if no translation was found, retry without context */
+ if (context_translated_value == context_value)
+ translated_value = g_dgettext (gettext_domain, entry->value);
+ else
+ translated_value = context_translated_value;
+
+ if (translated_value != entry->value)
+ {
+ if (codeset_is_set)
+ entry->glvalue = g_strdup (translated_value);
+ else
+ entry->glvalue = g_locale_to_utf8 (translated_value, -1,
+ NULL, NULL, NULL);
+ }
+
+ g_free (context_value);
+ }
+
+ g_free (gettext_domain);
+ }
+ }
+
return TRUE;
}
@@ -1047,6 +1156,10 @@ _xfce_rc_simple_read_entry (const XfceRc
if (best_value != NULL)
return best_value;
+ /* fall back to gettext translated value */
+ if (entry->glvalue != NULL)
+ return entry->glvalue;
+
/* FALL-THROUGH */
}