summaryrefslogtreecommitdiff
path: root/libappstream-glib/as-utils.c
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2014-03-17 19:57:22 +0000
committerRichard Hughes <richard@hughsie.com>2014-03-17 20:01:16 +0000
commit18111df9cd7dd2ec2bfe71e657bd1c810293289d (patch)
tree2e28c18413e23374a8268847d2b1df16cf6604bb /libappstream-glib/as-utils.c
parent267d9657d565f1cee7fd6e5c4c302883f7d4a356 (diff)
downloadappstream-glib-18111df9cd7dd2ec2bfe71e657bd1c810293289d.tar.gz
If locale is unspecified use the default user LANG choice
Diffstat (limited to 'libappstream-glib/as-utils.c')
-rw-r--r--libappstream-glib/as-utils.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/libappstream-glib/as-utils.c b/libappstream-glib/as-utils.c
index 4dfecdf..51f0e7e 100644
--- a/libappstream-glib/as-utils.c
+++ b/libappstream-glib/as-utils.c
@@ -136,3 +136,42 @@ out:
}
return formatted;
}
+
+/**
+ * as_hash_lookup_by_locale:
+ * @hash: a #GHashTable.
+ * @locale: the locale, or %NULL to use the users default local.
+ *
+ * Gets the 'best' data entry in a hash table using the user-set list
+ * of preferred languages.
+ *
+ * This is how methods like as_app_get_name(app,NULL) return the localized
+ * data for the user.
+ *
+ * Returns: the string value, or %NULL if there was no data
+ *
+ * Since: 0.1.0
+ **/
+const gchar *
+as_hash_lookup_by_locale (GHashTable *hash, const gchar *locale)
+{
+ const gchar *const *locales;
+ const gchar *tmp = NULL;
+ guint i;
+
+ /* the user specified a locale */
+ if (locale != NULL) {
+ tmp = g_hash_table_lookup (hash, locale);
+ goto out;
+ }
+
+ /* use LANGUAGE, LC_ALL, LC_MESSAGES and LANG */
+ locales = g_get_language_names ();
+ for (i = 0; locales[i] != NULL; i++) {
+ tmp = g_hash_table_lookup (hash, locales[i]);
+ if (tmp != NULL)
+ goto out;
+ }
+out:
+ return tmp;
+}