1
/* Some ELinks' auxiliary routines (ELinks<->gettext support) */
2
/* $Id: libintl.c,v 1.14 2003/12/22 22:00:08 pasky Exp $ */
13
#include "intl/gettext/libintl.h"
14
#include "intl/gettext/gettextP.h"
15
#include "util/error.h"
16
#include "util/memory.h"
17
#include "util/string.h"
19
/* This is a language lookup table. Indexed by code. */
20
/* Update this everytime you add a new translation. */
21
/* TODO: Try to autogenerate it somehow. Maybe just a complete table? Then we
22
* will anyway need a table of real translations. */
23
struct language languages[] = {
24
{N_("System"), "system"},
25
{N_("English"), "en"},
27
{N_("Belarusian"), "be"},
28
{N_("Brazilian Portuguese"), "pt-BR"},
29
{N_("Bulgarian"), "bg"},
30
{N_("Catalan"), "ca"},
31
{N_("Croatian"), "hr"},
35
{N_("Estonian"), "et"},
36
{N_("Finnish"), "fi"},
38
{N_("Galician"), "gl"},
41
{N_("Hungarian"), "hu"},
42
{N_("Icelandic"), "is"},
43
{N_("Indonesian"), "id"},
44
{N_("Italian"), "it"},
46
{N_("Lithuanian"), "lt"},
47
{N_("Norwegian"), "no"},
49
{N_("Portuguese"), "pt"},
50
{N_("Romanian"), "ro"},
51
{N_("Russian"), "ru"},
53
{N_("Spanish"), "es"},
54
{N_("Swedish"), "sv"},
55
{N_("Turkish"), "tr"},
56
{N_("Ukrainian"), "uk"},
61
/* XXX: In fact this is _NOT_ a real ISO639 code but RFC3066 code (as we're
62
* supposed to use that one when sending language tags through HTTP/1.1) and
63
* that one consists basically from ISO639[-ISO3166]. This is important for
65
/* TODO: We should reflect this in name of this function and of the tag. On the
66
* other side, it's ISO639 for gettext as well etc. So what? --pasky */
69
iso639_to_language(unsigned char *iso639)
71
unsigned char *l = stracpy(iso639);
78
/* The environment variable transformation. */
92
for (i = 0; languages[i].name; i++) {
93
if (strcmp(languages[i].iso639, l))
99
/* Base language match. */
103
for (i = 0; languages[i].name; i++) {
104
if (strcmp(languages[i].iso639, l))
111
/* Any dialect match. */
114
for (i = 0; languages[i].name; i++) {
115
int il = strcspn(languages[i].iso639, "-");
117
if (strncmp(languages[i].iso639, l, il > ll ? ll : il))
123
/* Default to english. */
129
int system_language = 0;
132
language_to_iso639(int language)
134
/* Language is "system", we need to extract the index from
137
return system_language ?
138
languages[system_language].iso639 :
139
languages[get_system_language_index()].iso639;
142
return languages[language].iso639;
146
name_to_language(unsigned char *name)
150
for (i = 0; languages[i].name; i++) {
151
if (strcasecmp(languages[i].name, name))
159
language_to_name(int language)
161
return languages[language].name;
165
get_system_language_index(void)
169
/* At this point current_language must be "system" yet. */
170
l = getenv("LANGUAGE");
172
l = getenv("LC_ALL");
174
l = getenv("LC_MESSAGES");
178
return (l) ? iso639_to_language(l) : 1;
181
int current_language = 0;
184
set_language(int language)
188
if (!system_language)
189
system_language = get_system_language_index();
191
if (language == current_language) {
196
current_language = language;
199
language = system_language;
202
/* We never free() this, purely intentionally. */
203
LANGUAGE = malloc(256);
205
strcpy(LANGUAGE, language_to_iso639(language));
206
p = strchr(LANGUAGE, '-');
210
/* Propagate the change to gettext. From the info manual. */
212
extern int _nl_msg_cat_cntr;