2008-08-14 00:51:18 +02:00
|
|
|
Add support of gettext for desktop entry files.
|
|
|
|
|
|
|
|
We only support this for the following keys: Name, GenericName, Comment. We
|
|
|
|
don't support all keys because it can create issues for the Icon key (which is
|
|
|
|
localizable -- which can result in a broken icon).
|
|
|
|
|
|
|
|
Translations that are present in the desktop entry take precedence over
|
|
|
|
translations via gettext. If we don't do this, then user modifications won't
|
|
|
|
appear since they will have lower precedence.
|
|
|
|
|
2008-09-13 05:33:41 +02:00
|
|
|
Index: gnome-desktop-2.23.91/libgnome-desktop/gnome-desktop-item.c
|
2008-08-14 00:51:18 +02:00
|
|
|
===================================================================
|
2008-09-13 05:33:41 +02:00
|
|
|
--- gnome-desktop-2.23.91.orig/libgnome-desktop/gnome-desktop-item.c
|
|
|
|
+++ gnome-desktop-2.23.91/libgnome-desktop/gnome-desktop-item.c
|
2008-08-14 00:51:18 +02:00
|
|
|
@@ -84,6 +84,7 @@ struct _GnomeDesktopItem {
|
|
|
|
GHashTable *main_hash;
|
|
|
|
|
|
|
|
char *location;
|
|
|
|
+ const char *gettext_domain;
|
|
|
|
|
|
|
|
time_t mtime;
|
|
|
|
|
|
|
|
@@ -139,6 +140,8 @@ static GnomeDesktopItem *gnome_desktop_i
|
|
|
|
|
|
|
|
static void update_recently_used_apps (const GnomeDesktopItem *item);
|
|
|
|
|
|
|
|
+static const char *lookup (const GnomeDesktopItem *item, const char *key);
|
|
|
|
+
|
|
|
|
static int
|
|
|
|
readbuf_getc (ReadBuf *rb)
|
|
|
|
{
|
|
|
|
@@ -399,6 +402,7 @@ gnome_desktop_item_new (void)
|
|
|
|
"1.0");
|
|
|
|
|
|
|
|
retval->launch_time = 0;
|
|
|
|
+ retval->gettext_domain = NULL;
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
2008-09-13 05:33:41 +02:00
|
|
|
@@ -477,6 +481,10 @@ gnome_desktop_item_copy (const GnomeDesk
|
2008-08-14 00:51:18 +02:00
|
|
|
copy_string_hash,
|
|
|
|
retval->main_hash);
|
|
|
|
|
|
|
|
+ retval->gettext_domain = lookup (retval, GNOME_DESKTOP_ITEM_GETTEXT_DOMAIN);
|
2008-09-13 05:33:41 +02:00
|
|
|
+ if (!retval->gettext_domain)
|
|
|
|
+ retval->gettext_domain = "desktop_translations";
|
2008-08-14 00:51:18 +02:00
|
|
|
+
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2008-09-13 05:33:41 +02:00
|
|
|
@@ -924,6 +932,9 @@ gnome_desktop_item_unref (GnomeDesktopIt
|
2008-08-14 00:51:18 +02:00
|
|
|
g_free (item->location);
|
|
|
|
item->location = NULL;
|
|
|
|
|
|
|
|
+ /* no need to free it, it's a const key */
|
|
|
|
+ item->gettext_domain = NULL;
|
|
|
|
+
|
|
|
|
g_free (item);
|
|
|
|
}
|
|
|
|
|
2008-09-13 05:33:41 +02:00
|
|
|
@@ -999,16 +1010,79 @@ lookup (const GnomeDesktopItem *item, co
|
2008-08-14 00:51:18 +02:00
|
|
|
static const char *
|
|
|
|
lookup_locale (const GnomeDesktopItem *item, const char *key, const char *locale)
|
|
|
|
{
|
|
|
|
+ const char *ret;
|
|
|
|
+
|
|
|
|
+ ret = NULL;
|
|
|
|
+
|
|
|
|
if (locale == NULL ||
|
|
|
|
strcmp (locale, "C") == 0) {
|
|
|
|
- return lookup (item, key);
|
|
|
|
+ ret = lookup (item, key);
|
|
|
|
} else {
|
|
|
|
- const char *ret;
|
|
|
|
char *full = g_strdup_printf ("%s[%s]", key, locale);
|
|
|
|
ret = lookup (item, full);
|
|
|
|
g_free (full);
|
|
|
|
- return ret;
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ /* 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. */
|
|
|
|
+ if (!ret && item->gettext_domain &&
|
|
|
|
+ (strcmp (key, GNOME_DESKTOP_ITEM_NAME) == 0 ||
|
|
|
|
+ strcmp (key, GNOME_DESKTOP_ITEM_GENERIC_NAME) == 0 ||
|
|
|
|
+ strcmp (key, GNOME_DESKTOP_ITEM_COMMENT) == 0)) {
|
|
|
|
+ const char *msg_locale = setlocale (LC_MESSAGES, NULL);
|
|
|
|
+
|
|
|
|
+ /* 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. */
|
|
|
|
+ if (msg_locale && locale &&
|
|
|
|
+ strcmp (msg_locale, locale) == 0) {
|
|
|
|
+ const char *value = lookup (item, key);
|
2008-09-13 05:33:41 +02:00
|
|
|
+
|
|
|
|
+ if (item->location && value != NULL && value[0] != '\0') {
|
|
|
|
+ GFile *file;
|
|
|
|
+ char *basename;
|
|
|
|
+
|
|
|
|
+ file = g_file_new_for_uri (item->location);
|
|
|
|
+ basename = g_file_get_basename (file);
|
|
|
|
+ g_object_unref (file);
|
|
|
|
+
|
|
|
|
+ if (basename) {
|
|
|
|
+ char *context;
|
|
|
|
+ char *context_value;
|
|
|
|
+
|
|
|
|
+ context = g_strdup_printf ("%s(%s)", key,
|
|
|
|
+ basename);
|
|
|
|
+ context_value = g_strdup_printf ("%s%s%s",
|
|
|
|
+ context, ": ", value);
|
|
|
|
+ ret = g_dgettext (item->gettext_domain,
|
|
|
|
+ context_value);
|
|
|
|
+ if (ret == context_value)
|
|
|
|
+ ret = NULL;
|
|
|
|
+
|
|
|
|
+ g_free (context_value);
|
|
|
|
+ g_free (context);
|
|
|
|
+ g_free (basename);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!ret && value != NULL && value[0] != '\0') {
|
|
|
|
+ ret = g_dgettext (item->gettext_domain, value);
|
2008-08-14 00:51:18 +02:00
|
|
|
+ /* don't accept no translation, since we might
|
|
|
|
+ * have something better later, with another
|
|
|
|
+ * locale */
|
|
|
|
+ if (ret == value)
|
|
|
|
+ ret = NULL;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
2008-09-13 05:33:41 +02:00
|
|
|
@@ -4039,6 +4113,10 @@ ditem_load (ReadBuf *rb,
|
2008-08-14 00:51:18 +02:00
|
|
|
|
|
|
|
readbuf_close (rb);
|
|
|
|
|
|
|
|
+ item->gettext_domain = lookup (item, GNOME_DESKTOP_ITEM_GETTEXT_DOMAIN);
|
2008-09-13 05:33:41 +02:00
|
|
|
+ if (!item->gettext_domain)
|
|
|
|
+ item->gettext_domain = "desktop_translations";
|
2008-08-14 00:51:18 +02:00
|
|
|
+
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2008-09-13 05:33:41 +02:00
|
|
|
Index: gnome-desktop-2.23.91/libgnome-desktop/libgnome/gnome-desktop-item.h
|
2008-08-14 00:51:18 +02:00
|
|
|
===================================================================
|
2008-09-13 05:33:41 +02:00
|
|
|
--- gnome-desktop-2.23.91.orig/libgnome-desktop/libgnome/gnome-desktop-item.h
|
|
|
|
+++ gnome-desktop-2.23.91/libgnome-desktop/libgnome/gnome-desktop-item.h
|
2008-08-14 00:51:18 +02:00
|
|
|
@@ -98,6 +98,7 @@ typedef struct _GnomeDesktopItem GnomeDe
|
|
|
|
#define GNOME_DESKTOP_ITEM_DOC_PATH "X-GNOME-DocPath" /* string */
|
|
|
|
#define GNOME_DESKTOP_ITEM_SUBSTITUTEUID "X-KDE-SubstituteUID" /*boolean*/
|
|
|
|
#define GNOME_DESKTOP_ITEM_ROOT_ONLY "X-KDE-RootOnly" /*boolean*/
|
|
|
|
+#define GNOME_DESKTOP_ITEM_GETTEXT_DOMAIN "X-SUSE-Gettext-Domain" /* string */
|
|
|
|
/* The vfolder proposal */
|
|
|
|
#define GNOME_DESKTOP_ITEM_CATEGORIES "Categories" /* string */
|
|
|
|
#define GNOME_DESKTOP_ITEM_ONLY_SHOW_IN "OnlyShowIn" /* string */
|