[glib/resources] Support per-locale resources
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/resources] Support per-locale resources
- Date: Thu, 22 Dec 2011 10:09:28 +0000 (UTC)
commit f46f859fd322cfefe00efcf8bec68e6388048f7d
Author: Alexander Larsson <alexl redhat com>
Date: Thu Dec 22 11:06:49 2011 +0100
Support per-locale resources
gio/gresource.c | 43 +++++++++++++++++++++++++++++++------------
1 files changed, 31 insertions(+), 12 deletions(-)
---
diff --git a/gio/gresource.c b/gio/gresource.c
index bcd2b99..4ec9c4d 100644
--- a/gio/gresource.c
+++ b/gio/gresource.c
@@ -131,6 +131,7 @@ static gboolean do_lookup (GResource *resource,
guint32 *flags,
const void **data,
gsize *data_size,
+ gboolean follow_locales,
GError **error)
{
gboolean free_path = FALSE;
@@ -163,15 +164,33 @@ static gboolean do_lookup (GResource *resource,
&_size,
&_flags,
&array);
- if (size)
- *size = _size;
- if (flags)
- *flags = _flags;
- if (data)
- *data = g_variant_get_data (array);
- if (data_size)
- *data_size = g_variant_get_size (array);
- res = TRUE;
+
+ if (follow_locales && _flags & G_RESOURCE_FLAGS_LOCALIZED)
+ {
+ const gchar * const *langs = g_get_language_names ();
+ int i;
+
+ for (i = 0; langs[i] != NULL; i++)
+ {
+ char *prefixed_path = g_strconcat ("/", langs[i], path, NULL);
+ res = do_lookup (resource, prefixed_path, size, flags, data, data_size, FALSE, NULL);
+ if (res)
+ break;
+ }
+ }
+
+ if (!res)
+ {
+ if (size)
+ *size = _size;
+ if (flags)
+ *flags = _flags;
+ if (data)
+ *data = g_variant_get_data (array);
+ if (data_size)
+ *data_size = g_variant_get_size (array);
+ res = TRUE;
+ }
}
if (free_path)
@@ -189,7 +208,7 @@ g_resource_open_stream (GResource *resource,
guint32 flags;
GInputStream *stream, *stream2;
- if (!do_lookup (resource, path, NULL, &flags, &data, &data_size, error))
+ if (!do_lookup (resource, path, NULL, &flags, &data, &data_size, TRUE, error))
return NULL;
stream = g_memory_input_stream_new_from_data (data, data_size, NULL);
@@ -221,7 +240,7 @@ g_resource_lookup_data (GResource *resource,
guint32 flags;
gsize data_size;
- if (!do_lookup (resource, path, size, &flags, &data, &data_size, error))
+ if (!do_lookup (resource, path, size, &flags, &data, &data_size, TRUE, error))
return NULL;
if (flags & G_RESOURCE_FLAGS_COMPRESSED)
@@ -242,7 +261,7 @@ g_resource_get_info (GResource *resource,
guint32 *flags,
GError **error)
{
- return do_lookup (resource, path, size, flags, NULL, NULL, error);
+ return do_lookup (resource, path, size, flags, NULL, NULL, TRUE, error);
}
char **
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]