summaryrefslogtreecommitdiff
path: root/pango/pango-utils.c
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@gnome.org>2006-12-06 23:00:31 +0000
committerBehdad Esfahbod <behdad@src.gnome.org>2006-12-06 23:00:31 +0000
commitf3507cc8cf4106cd4731c57b32092f5362883bdd (patch)
tree028c81ff5aa62a22f73b2b9c7a7bd13ac373f5bf /pango/pango-utils.c
parentb7c74a7787b624bdf1ef6a4f6dba2007317b9265 (diff)
downloadpango-f3507cc8cf4106cd4731c57b32092f5362883bdd.tar.gz
Bug 333982 – Fallback to $LANG whenever NULL PangoLanguage is used Patch
2006-12-06 Behdad Esfahbod <behdad@gnome.org> Bug 333982 – Fallback to $LANG whenever NULL PangoLanguage is used Patch from LingNing Zhang * docs/pango-sections.txt: * docs/tmpl/utils.sgml: * pango/pango-context.c: * pango/pango-types.h: * pango/pango-utils.c (_pango_get_lc_ctype), (pango_language_get_default): * pango/pango.def: New public function pango_language_get_default(). Note that, this does not make Pango fallback to the default language automatically, but the user can use this function to set the default language of the locale on a context: pango_context_set_language (context, pango_language_get_default());
Diffstat (limited to 'pango/pango-utils.c')
-rw-r--r--pango/pango-utils.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/pango/pango-utils.c b/pango/pango-utils.c
index 81700d2a..ea480840 100644
--- a/pango/pango-utils.c
+++ b/pango/pango-utils.c
@@ -24,6 +24,7 @@
#include <string.h>
#include <stdlib.h>
#include <math.h>
+#include <locale.h>
#include "pango-font.h"
#include "pango-impl-utils.h"
@@ -988,6 +989,92 @@ pango_language_get_type (void)
}
/**
+ * _pango_get_lc_ctype:
+ *
+ * Return the Unix-style locale string for the language currently in
+ * effect. On Unix systems, this is the return value from
+ * <literal>setlocale(LC_CTYPE, NULL)</literal>, and the user can
+ * affect this through the environment variables LC_ALL, LC_CTYPE or
+ * LANG (checked in that order). The locale strings typically is in
+ * the form lang_COUNTRY, where lang is an ISO-639 language code, and
+ * COUNTRY is an ISO-3166 country code. For instance, sv_FI for
+ * Swedish as written in Finland or pt_BR for Portuguese as written in
+ * Brazil.
+ *
+ * On Windows, the C library doesn't use any such environment
+ * variables, and setting them won't affect the behaviour of functions
+ * like ctime(). The user sets the locale through the Regional Options
+ * in the Control Panel. The C library (in the setlocale() function)
+ * does not use country and language codes, but country and language
+ * names spelled out in English.
+ * However, this function does check the above environment
+ * variables, and does return a Unix-style locale string based on
+ * either said environment variables or the thread's current locale.
+ *
+ * Return value: a dynamically allocated string, free with g_free().
+ */
+static gchar *
+_pango_get_lc_ctype (void)
+{
+#ifdef G_OS_WIN32
+ /* Somebody might try to set the locale for this process using the
+ * LANG or LC_ environment variables. The Microsoft C library
+ * doesn't know anything about them. You set the locale in the
+ * Control Panel. Setting these env vars won't have any affect on
+ * locale-dependent C library functions like ctime(). But just for
+ * kicks, do obey LC_ALL, LC_CTYPE and LANG in Pango. (This also makes
+ * it easier to test GTK and Pango in various default languages, you
+ * don't have to clickety-click in the Control Panel, you can simply
+ * start the program with LC_ALL=something on the command line.)
+ */
+
+ gchar *p;
+
+ p = getenv ("LC_ALL");
+ if (p != NULL)
+ return g_strdup (p);
+
+ p = getenv ("LC_CTYPE");
+ if (p != NULL)
+ return g_strdup (p);
+
+ p = getenv ("LANG");
+ if (p != NULL)
+ return g_strdup (p);
+
+ return g_win32_getlocale ();
+#else
+ return g_strdup (setlocale (LC_CTYPE, NULL));
+#endif
+}
+
+/**
+ * pango_language_get_default:
+ *
+ * Returns the #PangoLanguage for the current locale of the running
+ * process. Note that this can change over the life of an
+ * application.
+ *
+ * Return value: the default language as a #PangoLanguage, must not be
+ * freed.
+ *
+ * Since: 1.16
+ **/
+PangoLanguage *
+pango_language_get_default (void)
+{
+ gchar *lang;
+ PangoLanguage *result;
+
+ lang = _pango_get_lc_ctype ();
+
+ result = pango_language_from_string (lang);
+ g_free (lang);
+
+ return result;
+}
+
+/**
* pango_language_from_string:
* @language: a string representing a language tag
*
@@ -999,6 +1086,9 @@ pango_language_get_type (void)
* This function first canonicalizes the string by converting it to
* lowercase, mapping '_' to '-', and stripping all characters other
* than letters and '-'.
+ *
+ * Use pango_language_get_default() if you want to get the #PangoLanguage for
+ * the current locale of the process.
*
* Return value: an opaque pointer to a #PangoLanguage structure.
* this will be valid forever after.