diff options
author | Richard Hughes <richard@hughsie.com> | 2016-06-29 14:51:29 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2016-06-29 14:51:29 +0100 |
commit | 267f0f0bfad3cb47abca579fa7bb49bed438946f (patch) | |
tree | c1062afb9b416d409dbe89ea4125c574daa4d157 /libappstream-glib/as-app.c | |
parent | 0eb52a724adaff5ab666a42567f157caf5e45f6c (diff) | |
download | appstream-glib-267f0f0bfad3cb47abca579fa7bb49bed438946f.tar.gz |
Fall back to the country code in as_app_get_language()
Diffstat (limited to 'libappstream-glib/as-app.c')
-rw-r--r-- | libappstream-glib/as-app.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c index 4b5449b..2755e48 100644 --- a/libappstream-glib/as-app.c +++ b/libappstream-glib/as-app.c @@ -1398,16 +1398,29 @@ gint as_app_get_language (AsApp *app, const gchar *locale) { AsAppPrivate *priv = GET_PRIVATE (app); - gboolean ret; gpointer value = NULL; + g_auto(GStrv) lang = NULL; + /* fallback */ if (locale == NULL) locale = "C"; - ret = g_hash_table_lookup_extended (priv->languages, - locale, NULL, &value); - if (!ret) - return -1; - return GPOINTER_TO_INT (value); + + /* look up full locale */ + if (g_hash_table_lookup_extended (priv->languages, + locale, NULL, &value)) { + return GPOINTER_TO_INT (value); + } + + /* look up just country code */ + lang = g_strsplit (locale, "_", 2); + if (g_strv_length (lang) == 2 && + g_hash_table_lookup_extended (priv->languages, + lang[0], NULL, &value)) { + return GPOINTER_TO_INT (value); + } + + /* failed */ + return -1; } /** |