mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
Add g_get_locale_variants()
Make _g_compute_locale_variants() public as g_get_locale_variants(). Bug #635998.
This commit is contained in:
parent
be8899bfe6
commit
3d824065b8
@ -2730,6 +2730,7 @@ g_dpgettext2
|
||||
g_strip_context
|
||||
<SUBSECTION>
|
||||
g_get_language_names
|
||||
g_get_locale_variants
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
|
@ -72,6 +72,20 @@ test_language_names (void)
|
||||
NULL));
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user