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 = g_strdup(setlocale(LC_MONETARY, NULL));
49 size_t len = strcspn(locale,
".@");
50 char* sep = memchr(locale,
'_', len);
54 wchar_t *wlocale = g_utf8_to_utf16 (locale, len, NULL, NULL, NULL);
56 if (IsValidLocaleName(wlocale))
60 return LOCALE_NAME_USER_DEFAULT;
65get_lconv_wide_val (LCTYPE lctype)
67 static wchar_t buffer[BUFSIZE];
68 wchar_t* locale = get_locale_name ();
69 memset (buffer, 0, BUFSIZE *
sizeof(
wchar_t));
70 int count = GetLocaleInfoEx (locale, lctype, buffer, BUFSIZE);
73 g_error(
"GetLocaleInfo failed for %ld, %ld", lctype, GetLastError());
76 if (lctype == LOCALE_SGROUPING || lctype == LOCALE_SMONGROUPING)
86gnc_lconv_set_utf8 (
char **p_value,
char *default_value)
88 char *value = *p_value;
91 if ((value == NULL) || (value[0] == 0))
92 value = default_value;
94 *p_value = g_locale_to_utf8 (value, -1, NULL, NULL, NULL);
100 *p_value = default_value;
106gnc_lconv_set_char (
char *p_value,
char default_value)
108 if ((p_value != NULL) && (*p_value == CHAR_MAX))
109 *p_value = default_value;
115 static struct lconv lc;
116 static gboolean lc_set = FALSE;
123 gnc_lconv_set_utf8(&lc.decimal_point,
124 get_lconv_wide_val (LOCALE_SDECIMAL),
".");
125 gnc_lconv_set_utf8(&lc.thousands_sep,
126 get_lconv_wide_val (LOCALE_STHOUSAND),
",");
127 gnc_lconv_set_utf8(&lc.grouping,
128 get_lconv_wide_val (LOCALE_SGROUPING),
"\003");
129 gnc_lconv_set_utf8(&lc.int_curr_symbol,
130 get_lconv_wide_val (LOCALE_SINTLSYMBOL),
"USD ");
131 gnc_lconv_set_utf8(&lc.currency_symbol,
132 get_lconv_wide_val (LOCALE_SCURRENCY),
"$");
133 gnc_lconv_set_utf8(&lc.mon_decimal_point,
134 get_lconv_wide_val (LOCALE_SMONDECIMALSEP),
".");
135 gnc_lconv_set_utf8(&lc.mon_thousands_sep,
136 get_lconv_wide_val (LOCALE_SMONTHOUSANDSEP),
",");
137 gnc_lconv_set_utf8(&lc.mon_grouping,
138 get_lconv_wide_val (LOCALE_SMONGROUPING),
"\003");
139 gnc_lconv_set_utf8(&lc.negative_sign,
140 get_lconv_wide_val (LOCALE_SNEGATIVESIGN),
"-");
141 gnc_lconv_set_utf8(&lc.positive_sign,
142 get_lconv_wide_val (LOCALE_SPOSITIVESIGN),
"");
144 gnc_lconv_set_utf8(&lc.decimal_point,
".");
145 gnc_lconv_set_utf8(&lc.thousands_sep,
",");
146 gnc_lconv_set_utf8(&lc.grouping,
"\003");
147 gnc_lconv_set_utf8(&lc.int_curr_symbol,
"USD ");
148 gnc_lconv_set_utf8(&lc.currency_symbol,
"$");
149 gnc_lconv_set_utf8(&lc.mon_decimal_point,
".");
150 gnc_lconv_set_utf8(&lc.mon_thousands_sep,
",");
151 gnc_lconv_set_utf8(&lc.mon_grouping,
"\003");
152 gnc_lconv_set_utf8(&lc.negative_sign,
"-");
153 gnc_lconv_set_utf8(&lc.positive_sign,
"");
155 gnc_lconv_set_char(&lc.frac_digits, 2);
156 gnc_lconv_set_char(&lc.int_frac_digits, 2);
157 gnc_lconv_set_char(&lc.p_cs_precedes, 1);
158 gnc_lconv_set_char(&lc.p_sep_by_space, 0);
159 gnc_lconv_set_char(&lc.n_cs_precedes, 1);
160 gnc_lconv_set_char(&lc.n_sep_by_space, 0);
161 gnc_lconv_set_char(&lc.p_sign_posn, 1);
162 gnc_lconv_set_char(&lc.n_sign_posn, 1);
170gnc_locale_default_iso_currency_code (
void)
172 static char *code = NULL;
178 lc = gnc_localeconv ();
180 code = g_strdup (lc->int_curr_symbol);
193gnc_locale_decimal_places (
void)
195 static gboolean got_it = FALSE;
202 lc = gnc_localeconv();
203 places = lc->frac_digits;
212gchar *gnc_locale_name (
void)
215 return g_win32_getlocale();
217 return g_strdup (setlocale(LC_MONETARY, NULL));