2
* THIS FILE IS REMOVED FROM THE MAKEFILE BY OLIVIER
3
* THESE FUNCTIONS ARE NOT USED ANYWHERE !!!!!!!!
13
/* taken from gnome-libs/libgnome/gnome-i18n.c ... */
15
static GHashTable *alias_table = NULL;
17
/*read an alias file for the locales*/
18
static void read_aliases(char *file)
24
alias_table = g_hash_table_new(g_str_hash, g_str_equal);
25
fp = fopen(file, "r");
28
while (fgets(buf, 256, fp)) {
31
if (buf[0] == '#' || buf[0] == '\0')
33
p = strtok(buf, "\t ");
36
p = strtok(NULL, "\t ");
39
g_hash_table_insert(alias_table, g_strdup(buf), g_strdup(p));
44
static void free_alias_cb(gpointer key, gpointer value, gpointer user_data)
50
static void free_alias_table(void)
54
g_hash_table_foreach(alias_table, free_alias_cb, NULL);
55
g_hash_table_destroy(alias_table);
59
/*return the un-aliased language as a newly allocated string*/
60
static char *unalias_lang(char *lang)
65
read_aliases("/usr/share/locale/locale.alias");
66
read_aliases("/usr/local/share/locale/locale.alias");
67
read_aliases("/usr/lib/X11/locale/locale.alias");
68
read_aliases("/usr/openwin/lib/locale/locale.alias");
70
while ((p = g_hash_table_lookup(alias_table, lang)) && strcmp(p, lang))
75
/* Mask for components of locale spec. The ordering here is from
76
* least significant to most significant
79
COMPONENT_CODESET = 1 << 0,
80
COMPONENT_TERRITORY = 1 << 1,
81
COMPONENT_MODIFIER = 1 << 2
84
/* Break an X/Open style locale specification into components
86
static guint explode_locale(const gchar * locale, gchar ** language, gchar ** territory, gchar ** codeset, gchar ** modifier)
88
const gchar *uscore_pos;
94
uscore_pos = strchr(locale, '_');
95
dot_pos = strchr(uscore_pos ? uscore_pos : locale, '.');
96
at_pos = strchr(dot_pos ? dot_pos : (uscore_pos ? uscore_pos : locale), '@');
99
mask |= COMPONENT_MODIFIER;
100
*modifier = g_strdup(at_pos);
102
at_pos = locale + strlen(locale);
105
mask |= COMPONENT_CODESET;
106
*codeset = g_new(gchar, 1 + at_pos - dot_pos);
107
strncpy(*codeset, dot_pos, at_pos - dot_pos);
108
(*codeset)[at_pos - dot_pos] = '\0';
113
mask |= COMPONENT_TERRITORY;
114
*territory = g_new(gchar, 1 + dot_pos - uscore_pos);
115
strncpy(*territory, uscore_pos, dot_pos - uscore_pos);
116
(*territory)[dot_pos - uscore_pos] = '\0';
118
uscore_pos = dot_pos;
120
*language = g_new(gchar, 1 + uscore_pos - locale);
121
strncpy(*language, locale, uscore_pos - locale);
122
(*language)[uscore_pos - locale] = '\0';
128
* Compute all interesting variants for a given locale name -
129
* by stripping off different components of the value.
131
* For simplicity, we assume that the locale is in
132
* X/Open format: language[_territory][.codeset][@modifier]
134
* TODO: Extend this to handle the CEN format (see the GNUlibc docs)
135
* as well. We could just copy the code from glibc wholesale
136
* but it is big, ugly, and complicated, so I'm reluctant
137
* to do so when this should handle 99% of the time...
139
static GList *compute_locale_variants(const gchar * locale)
141
GList *retval = NULL;
151
g_return_val_if_fail(locale != NULL, NULL);
153
mask = explode_locale(locale, &language, &territory, &codeset, &modifier);
155
/* Iterate through all possible combinations, from least attractive
156
* to most attractive.
158
for (i = 0; i <= mask; i++)
159
if ((i & ~mask) == 0) {
160
gchar *val = g_strconcat(language,
161
(i & COMPONENT_TERRITORY) ? territory : "",
162
(i & COMPONENT_CODESET) ? codeset : "",
163
(i & COMPONENT_MODIFIER) ? modifier : "",
165
retval = g_list_prepend(retval, val);
169
if (mask & COMPONENT_CODESET)
171
if (mask & COMPONENT_TERRITORY)
173
if (mask & COMPONENT_MODIFIER)
179
/* The following is (partly) taken from the gettext package.
180
Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc. */
182
static const gchar *guess_category_value(const gchar * categoryname)
186
/* The highest priority value is the `LANGUAGE' environment
187
variable. This is a GNU extension. */
188
retval = getenv("LANGUAGE");
189
if (retval != NULL && retval[0] != '\0')
192
/* `LANGUAGE' is not set. So we have to proceed with the POSIX
193
methods of looking to `LC_ALL', `LC_xxx', and `LANG'. On some
194
systems this can be done by the `setlocale' function itself. */
196
/* Setting of LC_ALL overwrites all other. */
197
retval = getenv("LC_ALL");
198
if (retval != NULL && retval[0] != '\0')
201
/* Next comes the name of the desired category. */
202
retval = getenv(categoryname);
203
if (retval != NULL && retval[0] != '\0')
206
/* Last possibility is the LANG environment variable. */
207
retval = getenv("LANG");
208
if (retval != NULL && retval[0] != '\0')
214
static GList *get_language_list(const gchar * category_name)
217
gint c_locale_defined = FALSE;
219
const gchar *category_value;
220
gchar *category_memory, *orig_category_memory;
223
category_name = "LC_ALL";
225
category_value = guess_category_value(category_name);
227
category_value = "C";
228
orig_category_memory = category_memory = g_malloc(strlen(category_value) + 1);
230
while (category_value[0] != '\0') {
231
while (category_value[0] != '\0' && category_value[0] == ':')
234
if (category_value[0] != '\0') {
235
char *cp = category_memory;
237
while (category_value[0] != '\0' && category_value[0] != ':')
238
*category_memory++ = *category_value++;
240
category_memory[0] = '\0';
243
cp = unalias_lang(cp);
245
if (strcmp(cp, "C") == 0)
246
c_locale_defined = TRUE;
248
list = g_list_concat(list, compute_locale_variants(cp));
252
g_free(orig_category_memory);
254
if (!c_locale_defined)
255
list = g_list_append(list, "C");
262
GList *intl_get_language_list(void)
264
static GList *list = NULL;
268
list = gnome_i18n_get_language_list("LC_MESSAGES");
270
list = get_language_list("LC_MESSAGES");
277
/* low numbers are better */
278
int intl_score_locale(const gchar * locale)
280
GList *list = intl_get_language_list();
284
/* NULL is same as C locale */
286
return g_list_length(list) - 1;
287
for (tmp = list, i = 0; tmp; tmp = tmp->next, i++)
288
if (!strcmp((char *) tmp->data, locale))
290
if (!tmp) /* not found */