198 lines
6.7 KiB
Diff
198 lines
6.7 KiB
Diff
Index: glib/gkeyfile.c
|
|
===================================================================
|
|
--- glib/gkeyfile.c (révision 7473)
|
|
+++ glib/gkeyfile.c (copie de travail)
|
|
@@ -83,6 +83,8 @@ struct _GKeyFile
|
|
GKeyFileFlags flags;
|
|
|
|
gchar **locales;
|
|
+ gchar *gettext_domain;
|
|
+ gchar *file_basename;
|
|
};
|
|
|
|
typedef struct _GKeyFileKeyValuePair GKeyFileKeyValuePair;
|
|
@@ -209,6 +211,8 @@ 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;
|
|
+ key_file->file_basename = NULL;
|
|
}
|
|
|
|
static void
|
|
@@ -228,6 +232,18 @@ 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;
|
|
+ }
|
|
+
|
|
+ if (key_file->file_basename)
|
|
+ {
|
|
+ g_free (key_file->file_basename);
|
|
+ key_file->file_basename = NULL;
|
|
+ }
|
|
+
|
|
tmp = key_file->groups;
|
|
while (tmp != NULL)
|
|
{
|
|
@@ -448,6 +464,14 @@ 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);
|
|
+
|
|
+ if (!key_file->gettext_domain)
|
|
+ key_file->gettext_domain = g_strdup ("desktop_translations");
|
|
+
|
|
return TRUE;
|
|
}
|
|
|
|
@@ -497,6 +521,8 @@ g_key_file_load_from_file (GKeyFile
|
|
return FALSE;
|
|
}
|
|
|
|
+ key_file->file_basename = g_path_get_basename (file);
|
|
+
|
|
return TRUE;
|
|
}
|
|
|
|
@@ -554,6 +580,13 @@ 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);
|
|
+ if (!key_file->gettext_domain)
|
|
+ key_file->gettext_domain = g_strdup ("desktop_translations");
|
|
+
|
|
return TRUE;
|
|
}
|
|
|
|
@@ -623,6 +656,9 @@ g_key_file_load_from_dirs (GKeyFile
|
|
}
|
|
}
|
|
|
|
+ if (found_file)
|
|
+ key_file->file_basename = g_path_get_basename (output_path);
|
|
+
|
|
if (found_file && full_path)
|
|
*full_path = output_path;
|
|
else
|
|
@@ -1653,6 +1689,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 +1720,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 +1752,60 @@ 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)
|
|
+ {
|
|
+ const gchar *translated;
|
|
+ gboolean has_gettext;
|
|
+
|
|
+ translated = NULL;
|
|
+
|
|
+ /* first try to translate with the context */
|
|
+ if (key_file->file_basename)
|
|
+ {
|
|
+ gchar *context;
|
|
+ gchar *context_value;
|
|
+
|
|
+ context = g_strdup_printf ("%s(%s)", key,
|
|
+ key_file->file_basename);
|
|
+ context_value = g_strdup_printf ("%s%s%s",
|
|
+ context, ": ", orig_value);
|
|
+
|
|
+ translated = g_dgettext (key_file->gettext_domain,
|
|
+ context_value);
|
|
+ has_gettext = translated != context_value;
|
|
+
|
|
+ g_free (context_value);
|
|
+ g_free (context);
|
|
+ }
|
|
+
|
|
+ /* no translation with the context: try without context */
|
|
+ if (!has_gettext)
|
|
+ {
|
|
+ translated = g_dgettext (key_file->gettext_domain,
|
|
+ orig_value);
|
|
+ has_gettext = translated != orig_value;
|
|
+ }
|
|
+
|
|
+ g_free (orig_value);
|
|
+
|
|
+ if (has_gettext)
|
|
+ {
|
|
+ if (bind_textdomain_codeset (key_file->gettext_domain, NULL))
|
|
+ translated_value = g_strdup (translated);
|
|
+ else
|
|
+ translated_value = g_locale_to_utf8 (translated,
|
|
+ -1, NULL, NULL, NULL);
|
|
+ break;
|
|
+ }
|
|
+ else
|
|
+ translated_value = NULL;
|
|
+ }
|
|
+ }
|
|
}
|
|
|
|
/* Fallback to untranslated key
|
|
Index: glib/gkeyfile.h
|
|
===================================================================
|
|
--- glib/gkeyfile.h (révision 7473)
|
|
+++ glib/gkeyfile.h (copie de travail)
|
|
@@ -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"
|