25#include "gnc-locale-utils.h"
28#include <glib/gi18n.h>
34gnc_lconv_set_utf8 (
char **p_value,
wchar_t *w_value,
const char *default_value)
36 g_return_if_fail (p_value != NULL);
37 if (w_value && *w_value)
38 *p_value = g_utf16_to_utf8 (w_value, -1, NULL, NULL, NULL);
40 *p_value = g_strdup (default_value);
46 char* locale = setlocale(LC_MONETARY, NULL);
48 len = strchr (locale,
'.') - locale;
50 wchar_t *wlocale = g_utf8_to_utf16 (locale, len, NULL, NULL, NULL);
51 if (IsValidLocaleName(wlocale))
53 return LOCALE_NAME_USER_DEFAULT;
58get_lconv_wide_val (LCTYPE lctype)
60 static wchar_t buffer[BUFSIZE];
61 LPCWSTR locale = get_locale_name ();
62 memset (buffer, 0, BUFSIZE *
sizeof(
wchar_t));
63 int count = GetLocaleInfoEx (locale, lctype, buffer, BUFSIZE);
66 g_error(
"GetLocaleInfo failed for %ld, %ld", lctype, GetLastError());
69 if (lctype == LOCALE_SGROUPING || lctype == LOCALE_SMONGROUPING)
78gnc_lconv_set_utf8 (
char **p_value,
char *default_value)
80 char *value = *p_value;
83 if ((value == NULL) || (value[0] == 0))
84 value = default_value;
86 *p_value = g_locale_to_utf8 (value, -1, NULL, NULL, NULL);
92 *p_value = default_value;
98gnc_lconv_set_char (
char *p_value,
char default_value)
100 if ((p_value != NULL) && (*p_value == CHAR_MAX))
101 *p_value = default_value;
107 static struct lconv lc;
108 static gboolean lc_set = FALSE;
115 gnc_lconv_set_utf8(&lc.decimal_point,
116 get_lconv_wide_val (LOCALE_SDECIMAL),
".");
117 gnc_lconv_set_utf8(&lc.thousands_sep,
118 get_lconv_wide_val (LOCALE_STHOUSAND),
",");
119 gnc_lconv_set_utf8(&lc.grouping,
120 get_lconv_wide_val (LOCALE_SGROUPING),
"\003");
121 gnc_lconv_set_utf8(&lc.int_curr_symbol,
122 get_lconv_wide_val (LOCALE_SINTLSYMBOL),
"USD ");
123 gnc_lconv_set_utf8(&lc.currency_symbol,
124 get_lconv_wide_val (LOCALE_SCURRENCY),
"$");
125 gnc_lconv_set_utf8(&lc.mon_decimal_point,
126 get_lconv_wide_val (LOCALE_SMONDECIMALSEP),
".");
127 gnc_lconv_set_utf8(&lc.mon_thousands_sep,
128 get_lconv_wide_val (LOCALE_SMONTHOUSANDSEP),
",");
129 gnc_lconv_set_utf8(&lc.mon_grouping,
130 get_lconv_wide_val (LOCALE_SMONGROUPING),
"\003");
131 gnc_lconv_set_utf8(&lc.negative_sign,
132 get_lconv_wide_val (LOCALE_SNEGATIVESIGN),
"-");
133 gnc_lconv_set_utf8(&lc.positive_sign,
134 get_lconv_wide_val (LOCALE_SPOSITIVESIGN),
"");
136 gnc_lconv_set_utf8(&lc.decimal_point,
".");
137 gnc_lconv_set_utf8(&lc.thousands_sep,
",");
138 gnc_lconv_set_utf8(&lc.grouping,
"\003");
139 gnc_lconv_set_utf8(&lc.int_curr_symbol,
"USD ");
140 gnc_lconv_set_utf8(&lc.currency_symbol,
"$");
141 gnc_lconv_set_utf8(&lc.mon_decimal_point,
".");
142 gnc_lconv_set_utf8(&lc.mon_thousands_sep,
",");
143 gnc_lconv_set_utf8(&lc.mon_grouping,
"\003");
144 gnc_lconv_set_utf8(&lc.negative_sign,
"-");
145 gnc_lconv_set_utf8(&lc.positive_sign,
"");
147 gnc_lconv_set_char(&lc.frac_digits, 2);
148 gnc_lconv_set_char(&lc.int_frac_digits, 2);
149 gnc_lconv_set_char(&lc.p_cs_precedes, 1);
150 gnc_lconv_set_char(&lc.p_sep_by_space, 0);
151 gnc_lconv_set_char(&lc.n_cs_precedes, 1);
152 gnc_lconv_set_char(&lc.n_sep_by_space, 0);
153 gnc_lconv_set_char(&lc.p_sign_posn, 1);
154 gnc_lconv_set_char(&lc.n_sign_posn, 1);
162gnc_locale_default_iso_currency_code (
void)
164 static char *code = NULL;
170 lc = gnc_localeconv ();
172 code = g_strdup (lc->int_curr_symbol);
185gnc_locale_decimal_places (
void)
187 static gboolean got_it = FALSE;
194 lc = gnc_localeconv();
195 places = lc->frac_digits;
204gchar *gnc_locale_name (
void)
207 return g_win32_getlocale();
209 return g_strdup (setlocale(LC_MONETARY, NULL));