source: trunk/third/libgnome/libgnome/gnome-i18n.c @ 20807

Revision 20807, 3.4 KB checked in by ghudson, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r20806, which included commits to RCS files with non-trunk default branches.
Line 
1/*
2 * Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation
3 * All rights reserved.
4 *
5 * This file is part of the Gnome Library.
6 *
7 * The Gnome Library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
11 *
12 * The Gnome Library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with the Gnome Library; see the file COPYING.LIB.  If not,
19 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22/*
23  @NOTATION@
24 */
25
26#include <config.h>
27#include <string.h>
28#include <stdio.h>
29#include <locale.h>
30
31#include "gnome-i18nP.h"
32
33/* Doing it this way since this is declared in bonobo-activation-private.h */
34extern const GList * bonobo_activation_i18n_get_language_list (const gchar *category_name);
35
36/**
37 * gnome_i18n_get_language_list:
38 * @category_name: Name of category to look up, e.g. %"LC_MESSAGES".
39 *
40 * This computes a list of language strings that the user wants.  It searches in
41 * the standard environment variables to find the list, which is sorted in order
42 * from most desirable to least desirable.  The `C' locale is appended to the
43 * list if it does not already appear (other routines depend on this
44 * behaviour). If @category_name is %NULL, then %LC_ALL is assumed.
45 *
46 * Return value: the list of languages, this list should not be freed as it is
47 * owned by gnome-i18n.
48 **/
49const GList *
50gnome_i18n_get_language_list (const gchar *category_name)
51{
52  return bonobo_activation_i18n_get_language_list (category_name);
53}
54
55static int numeric_c_locale_depth = 0;
56static char *numeric_locale = NULL;
57
58/**
59 * gnome_i18n_push_c_numeric_locale:
60 *
61 * Description:  Saves the current LC_NUMERIC locale and sets it to "C"
62 * This way you can safely read write floating point numbers all in the
63 * same format.  You should make sure that code between
64 * gnome_i18n_push_c_numeric_locale() and gnome_i18n_pop_c_numeric_locale()
65 * doesn't do any setlocale calls or locale may end up in a strange setting.
66 * Also make sure to always pop the c numeric locale after you've pushed it.
67 * The calls can be nested.
68 **/
69void
70gnome_i18n_push_c_numeric_locale (void)
71{
72        if (numeric_c_locale_depth == 0) {
73                g_free (numeric_locale);
74                numeric_locale = g_strdup (setlocale (LC_NUMERIC, NULL));
75                setlocale (LC_NUMERIC, "C");
76        }
77        numeric_c_locale_depth ++;
78}
79
80/**
81 * gnome_i18n_pop_c_numeric_locale:
82 *
83 * Description:  Restores the LC_NUMERIC locale to what it was
84 * before the matching gnome_i18n_push_c_numeric_locale(). If these calls
85 * were nested, then this is a no-op until we get to the most outermost
86 * layer. Code in between these should not do any setlocale calls
87 * to change the LC_NUMERIC locale or things may come out very strange.
88 **/
89void
90gnome_i18n_pop_c_numeric_locale (void)
91{
92        if (numeric_c_locale_depth == 0) {
93                return;
94        }
95
96        numeric_c_locale_depth --;
97
98        if (numeric_c_locale_depth == 0) {
99                setlocale (LC_NUMERIC, numeric_locale);
100                g_free (numeric_locale);
101                numeric_locale = NULL;
102        }
103}
Note: See TracBrowser for help on using the repository browser.