mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-23 18:52:09 +01:00
l10n for gsettings
This commit is contained in:
parent
193c926d8a
commit
2f9292fb84
@ -11,6 +11,7 @@
|
||||
#include "config.h"
|
||||
#include <glib.h>
|
||||
#include <glibintl.h>
|
||||
#include <locale.h>
|
||||
|
||||
#include "gsettings.h"
|
||||
|
||||
@ -587,13 +588,66 @@ GVariant *
|
||||
g_settings_get_value (GSettings *settings,
|
||||
const gchar *key)
|
||||
{
|
||||
GVariant *value, *options;
|
||||
const GVariantType *type;
|
||||
GVariant *value;
|
||||
gint lc_category = -1;
|
||||
GVariant *sval;
|
||||
gchar *path;
|
||||
|
||||
sval = g_settings_schema_get_value (settings->priv->schema, key, &options);
|
||||
|
||||
if G_UNLIKELY (sval == NULL)
|
||||
g_error ("schema '%s' does not contain a key named '%s'\n",
|
||||
settings->priv->schema_name, key);
|
||||
|
||||
if (options != NULL)
|
||||
{
|
||||
GVariantIter iter;
|
||||
const gchar *key;
|
||||
GVariant *value;
|
||||
|
||||
g_variant_iter_init (&iter, options);
|
||||
while (g_variant_iter_loop (&iter, "{sv}", &key, &value))
|
||||
{
|
||||
if (strcmp (key, "l10n") == 0 &&
|
||||
g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
|
||||
{
|
||||
const gchar *category = g_variant_get_string (value, NULL);
|
||||
|
||||
if (strcmp (category, "ctype") == 0)
|
||||
lc_category = LC_CTYPE;
|
||||
else if (strcmp (category, "numeric") == 0)
|
||||
lc_category = LC_NUMERIC;
|
||||
else if (strcmp (category, "time") == 0)
|
||||
lc_category = LC_TIME;
|
||||
else if (strcmp (category, "collate") == 0)
|
||||
lc_category = LC_COLLATE;
|
||||
else if (strcmp (category, "monetary") == 0)
|
||||
lc_category = LC_MONETARY;
|
||||
else if (strcmp (category, "messages") == 0)
|
||||
lc_category = LC_MESSAGES;
|
||||
else if (strcmp (category, "all") == 0)
|
||||
lc_category = LC_ALL;
|
||||
else if (strcmp (category, "paper") == 0)
|
||||
lc_category = LC_PAPER;
|
||||
else if (strcmp (category, "name") == 0)
|
||||
lc_category = LC_NAME;
|
||||
else if (strcmp (category, "address") == 0)
|
||||
lc_category = LC_ADDRESS;
|
||||
else if (strcmp (category, "telephone") == 0)
|
||||
lc_category = LC_TELEPHONE;
|
||||
else if (strcmp (category, "measurement") == 0)
|
||||
lc_category = LC_MEASUREMENT;
|
||||
else if (strcmp (category, "identification") == 0)
|
||||
lc_category = LC_IDENTIFICATION;
|
||||
else
|
||||
g_error ("schema requests unsupported l10n category: %s",
|
||||
category);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
path = g_strconcat (settings->priv->path, key, NULL);
|
||||
sval = g_settings_schema_get_value (settings->priv->schema, key, NULL);
|
||||
type = g_variant_get_type (sval);
|
||||
value = g_settings_backend_read (settings->priv->backend, path, type);
|
||||
g_free (path);
|
||||
@ -605,7 +659,22 @@ g_settings_get_value (GSettings *settings,
|
||||
}
|
||||
|
||||
if (value == NULL)
|
||||
value = g_variant_ref (sval);
|
||||
{
|
||||
|
||||
if (lc_category != -1)
|
||||
{
|
||||
const gchar *domain;
|
||||
|
||||
domain = g_settings_schema_get_gettext_domain (settings->priv->schema);
|
||||
|
||||
value = g_variant_ref_sink (g_variant_new_string (
|
||||
dcgettext (domain,
|
||||
g_variant_get_string (sval, NULL),
|
||||
lc_category)));
|
||||
}
|
||||
else
|
||||
value = g_variant_ref (sval);
|
||||
}
|
||||
|
||||
g_variant_unref (sval);
|
||||
|
||||
|
@ -203,6 +203,25 @@ g_settings_schema_get_path (GSettingsSchema *schema)
|
||||
return result;
|
||||
}
|
||||
|
||||
const gchar *
|
||||
g_settings_schema_get_gettext_domain (GSettingsSchema *schema)
|
||||
{
|
||||
const gchar *result;
|
||||
GVariant *value;
|
||||
|
||||
value = gvdb_table_get_value (schema->priv->table, ".gettext-domain", NULL);
|
||||
|
||||
if (value && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
|
||||
{
|
||||
result = g_variant_get_string (value, NULL);
|
||||
g_variant_unref (value);
|
||||
}
|
||||
else
|
||||
result = NULL;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
gboolean
|
||||
g_settings_schema_has_key (GSettingsSchema *schema,
|
||||
const gchar *key)
|
||||
|
@ -56,6 +56,7 @@ struct _GSettingsSchema
|
||||
GType g_settings_schema_get_type (void);
|
||||
GSettingsSchema * g_settings_schema_new (const gchar *name);
|
||||
const gchar * g_settings_schema_get_path (GSettingsSchema *schema);
|
||||
const gchar * g_settings_schema_get_gettext_domain (GSettingsSchema *schema);
|
||||
GVariant * g_settings_schema_get_value (GSettingsSchema *schema,
|
||||
const gchar *key,
|
||||
GVariant **options);
|
||||
|
Loading…
x
Reference in New Issue
Block a user