[gnome-desktop/wip/locale-info: 1/10] gnome-languages: Add methods to get language/country from ISO codes
- From: Rui Matos <rtcm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-desktop/wip/locale-info: 1/10] gnome-languages: Add methods to get language/country from ISO codes
- Date: Tue, 5 Feb 2013 00:54:32 +0000 (UTC)
commit a14e2a812625103af3ad2b08e65e1c857acb80f1
Author: Rui Matos <tiagomatos gmail com>
Date: Sat Jan 26 17:13:55 2013 +0100
gnome-languages: Add methods to get language/country from ISO codes
https://bugzilla.gnome.org/show_bug.cgi?id=692700
libgnome-desktop/gnome-languages.c | 72 +++++++++++++++++++++++++++++-------
libgnome-desktop/gnome-languages.h | 4 ++
2 files changed, 62 insertions(+), 14 deletions(-)
---
diff --git a/libgnome-desktop/gnome-languages.c b/libgnome-desktop/gnome-languages.c
index 7b2b592..c3d3775 100644
--- a/libgnome-desktop/gnome-languages.c
+++ b/libgnome-desktop/gnome-languages.c
@@ -1051,6 +1051,9 @@ languages_variant_init (const char *variant)
static void
languages_init (void)
{
+ if (gnome_languages_map)
+ return;
+
gnome_languages_map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
languages_variant_init ("iso_639");
@@ -1065,6 +1068,9 @@ territories_init (void)
char *buf;
gsize buf_len;
+ if (gnome_territories_map)
+ return;
+
bindtextdomain ("iso_3166", ISO_CODES_LOCALESDIR);
bind_textdomain_codeset ("iso_3166", "UTF-8");
@@ -1123,13 +1129,8 @@ gnome_get_language_from_name (const char *name,
full_language = g_string_new (NULL);
- if (gnome_languages_map == NULL) {
- languages_init ();
- }
-
- if (gnome_territories_map == NULL) {
- territories_init ();
- }
+ languages_init ();
+ territories_init ();
language_code = NULL;
territory_code = NULL;
@@ -1215,13 +1216,8 @@ gnome_get_region_from_name (const char *name,
full_name = g_string_new (NULL);
- if (gnome_languages_map == NULL) {
- languages_init ();
- }
-
- if (gnome_territories_map == NULL) {
- territories_init ();
- }
+ languages_init ();
+ territories_init ();
language_code = NULL;
territory_code = NULL;
@@ -1305,3 +1301,51 @@ gnome_get_all_language_names (void)
return (char **) g_ptr_array_free (array, FALSE);
}
+
+/**
+ * gnome_get_language_from_code:
+ * @code: an ISO 639 code string
+ * @locale: (allow-none): a locale string
+ *
+ * Gets the language name for @code. If @locale is provided the
+ * returned string is translated accordingly.
+ *
+ * Return value: (transfer full): the language name. Caller takes
+ * ownership.
+ *
+ * Since: 3.8
+ */
+char *
+gnome_get_language_from_code (const char *code,
+ const char *locale)
+{
+ g_return_val_if_fail (code != NULL, NULL);
+
+ languages_init ();
+
+ return get_translated_language (code, locale);
+}
+
+/**
+ * gnome_get_country_from_code:
+ * @code: an ISO 3166 code string
+ * @locale: (allow-none): a locale string
+ *
+ * Gets the country name for @code. If @locale is provided the
+ * returned string is translated accordingly.
+ *
+ * Return value: (transfer full): the country name. Caller takes
+ * ownership.
+ *
+ * Since: 3.8
+ */
+char *
+gnome_get_country_from_code (const char *code,
+ const char *locale)
+{
+ g_return_val_if_fail (code != NULL, NULL);
+
+ territories_init ();
+
+ return get_translated_territory (code, locale);
+}
diff --git a/libgnome-desktop/gnome-languages.h b/libgnome-desktop/gnome-languages.h
index 2a05dfd..6b28b85 100644
--- a/libgnome-desktop/gnome-languages.h
+++ b/libgnome-desktop/gnome-languages.h
@@ -42,6 +42,10 @@ gboolean gnome_parse_language_name (const char *name,
char **modifierp);
char * gnome_normalize_language_name (const char *name);
gboolean gnome_language_has_translations (const char *language_name);
+char * gnome_get_language_from_code (const char *code,
+ const char *locale);
+char * gnome_get_country_from_code (const char *code,
+ const char *locale);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]