[glib] Add g_get_locale_variants()
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Add g_get_locale_variants()
- Date: Wed, 5 Jan 2011 21:58:27 +0000 (UTC)
commit 3d824065b847f2702aa312c51734328fc414af5a
Author: Christian Persch <chpe gnome org>
Date: Sun Nov 28 18:49:04 2010 +0100
Add g_get_locale_variants()
Make _g_compute_locale_variants() public as g_get_locale_variants().
Bug #635998.
docs/reference/glib/glib-sections.txt | 1 +
glib/gkeyfile.c | 5 ++---
glib/glib.symbols | 1 +
glib/gutils.c | 23 ++++++++++++++++++++++-
glib/gutils.h | 2 ++
glib/tests/utils.c | 15 +++++++++++++++
6 files changed, 43 insertions(+), 4 deletions(-)
---
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index 05ba4f8..c45ee67 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -2730,6 +2730,7 @@ g_dpgettext2
g_strip_context
<SUBSECTION>
g_get_language_names
+g_get_locale_variants
</SECTION>
<SECTION>
diff --git a/glib/gkeyfile.c b/glib/gkeyfile.c
index db90062..1f2a856 100644
--- a/glib/gkeyfile.c
+++ b/glib/gkeyfile.c
@@ -26,6 +26,7 @@
#include "config.h"
#include "gkeyfile.h"
+#include "gutils.h"
#include <errno.h>
#include <fcntl.h>
@@ -1630,8 +1631,6 @@ g_key_file_set_locale_string (GKeyFile *key_file,
g_free (value);
}
-extern gchar **_g_compute_locale_variants (const gchar *locale);
-
/**
* g_key_file_get_locale_string:
* @key_file: a #GKeyFile
@@ -1677,7 +1676,7 @@ g_key_file_get_locale_string (GKeyFile *key_file,
if (locale)
{
- languages = _g_compute_locale_variants (locale);
+ languages = g_get_locale_variants (locale);
free_languages = TRUE;
}
else
diff --git a/glib/glib.symbols b/glib/glib.symbols
index 0c4b0d1..4591ecd 100644
--- a/glib/glib.symbols
+++ b/glib/glib.symbols
@@ -1657,6 +1657,7 @@ g_setenv_utf8
g_get_home_dir_utf8
#endif
g_get_language_names
+g_get_locale_variants
g_get_prgname
#ifndef _WIN64
g_get_real_name PRIVATE
diff --git a/glib/gutils.c b/glib/gutils.c
index 3e01dae..5512fd4 100644
--- a/glib/gutils.c
+++ b/glib/gutils.c
@@ -3201,8 +3201,29 @@ append_locale_variants (GPtrArray *array,
g_free (modifier);
}
+/**
+ * g_get_locale_variants:
+ * @locale: a locale identifier
+ *
+ * Returns a list of derived variants of @locale, which can be used to
+ * e.g. construct locale-dependent filenames or search paths. The returned
+ * list is sorted from most desirable to least desirable.
+ * This function handles territory, charset and extra locale modifiers.
+ *
+ * For example, if @locale is "fr_BE", then the returned list
+ * is "fr_BE", "fr".
+ *
+ * If you need the list of variants for the <emphasis>current locale</emphasis>,
+ * use g_get_language_names().
+ *
+ * Returns: (transfer full) (array zero-terminated="1") (element-type utf8): a newly
+ * allocated array of newly allocated strings with the locale variants. Free with
+ * g_strfreev().
+ *
+ * Since: 2.28
+ */
gchar **
-_g_compute_locale_variants (const gchar *locale)
+g_get_locale_variants (const gchar *locale)
{
GPtrArray *array;
diff --git a/glib/gutils.h b/glib/gutils.h
index e4d8277..6b94efd 100644
--- a/glib/gutils.h
+++ b/glib/gutils.h
@@ -157,6 +157,8 @@ const gchar * g_get_user_runtime_dir (void);
G_CONST_RETURN gchar* G_CONST_RETURN * g_get_language_names (void);
+gchar **g_get_locale_variants (const gchar *locale);
+
/**
* GUserDirectory:
* @G_USER_DIRECTORY_DESKTOP: the user's Desktop directory
diff --git a/glib/tests/utils.c b/glib/tests/utils.c
index f586aa1..cf7d8dd 100644
--- a/glib/tests/utils.c
+++ b/glib/tests/utils.c
@@ -73,6 +73,20 @@ test_language_names (void)
}
static void
+test_locale_variants (void)
+{
+ char **v;
+
+ v = g_get_locale_variants ("fr_BE");
+ g_assert (strv_check ((const gchar * const *) v, "fr_BE", "fr", NULL));
+ g_strfreev (v);
+
+ v = g_get_locale_variants ("sr_SR latin");
+ g_assert (strv_check ((const gchar * const *) v, "sr_SR latin", "sr latin", "sr_SR", "sr", NULL));
+ g_strfreev (v);
+}
+
+static void
test_version (void)
{
g_print ("(header %d.%d.%d library %d.%d.%d) ",
@@ -152,6 +166,7 @@ main (int argc,
g_test_bug_base ("http://bugzilla.gnome.org/");
g_test_add_func ("/utils/language-names", test_language_names);
+ g_test_add_func ("/utils/locale-variants", test_locale_variants);
g_test_add_func ("/utils/version", test_version);
g_test_add_func ("/utils/appname", test_appname);
g_test_add_func ("/utils/tmpdir", test_tmpdir);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]