]> code.citadel.org Git - citadel.git/blob - webcit/gettext.c
* Re-enabled browser language detection. This will be debugged and finalized.
[citadel.git] / webcit / gettext.c
1 #define _GNU_SOURCE
2 #include "webcit.h"
3 #include "webserver.h"
4
5 #ifdef ENABLE_NLS
6
7 static const char *AvailLang[] = {
8         "de_DE"
9 };
10
11 /* TODO: we skip the language weightening so far. */
12 /* Accept-Language: 'de-de,en-us;q=0.7,en;q=0.3' */
13 void httplang_to_locale(const char *LocaleString)
14 {
15         char *locale = "C";
16         char *wanted_locales[10];
17         int i = 0;
18         int j = 0;
19         size_t len = strlen(LocaleString);
20         int nFound = 0;
21         int nAvail = 1;
22         char *search = (char *) malloc(len);
23         int done = 0;
24         //      char *mo;
25         //      char *webcitdir = WEBCITDIR;
26         locale_t my_Locale;
27         locale_t my_Empty_Locale;
28         memcpy(search, LocaleString, len);
29         search[len + 1] = '\0';
30         len = strlen(search);
31         /* the web browser sends '-', we need '_' */
32         for (i = 0; i < len; i++)
33                 if (search[i] == '-')
34                         search[i] = '_';
35         i = 0;
36         while ((search[i] != '\0') && !done && (nFound < 10)) {
37                 if ((search[i] == ',') || (search[i] == ';'))
38                 {
39                         if (search[i] == ';')
40                                 done = 1;
41                         search[i] = '\0';
42                         wanted_locales[nFound] = (char *) &search[j];
43                         j = i + 1;
44                         nFound++;
45                 }
46
47                 i++;
48         }
49         /* todo: weight  */
50
51         for (i = 0; i <= nFound; i++) {
52                 for (j = 0; j < nAvail; j++) {
53                         int ret = strncasecmp(wanted_locales[i],
54                                               AvailLang[j],
55                                               strlen(wanted_locales[i]));
56                         if (!ret) {
57                                 locale = (char *) AvailLang[j]; //wanted_locales[i];
58                                 i = nFound + 1;
59                                 j = nAvail + 1;
60                                 continue;
61                         }
62
63                 }
64         }
65
66         len = strlen(locale);
67         memcpy(search, locale, len);
68         memcpy(&search[len], ".UTF8", 5);
69         search[len + 5] = '\0';
70         my_Empty_Locale = newlocale(LC_ALL_MASK, NULL, NULL);   /* create default locale */
71         my_Locale = newlocale(LC_MESSAGES_MASK /*|LC_TIME_MASK FIXME */ ,
72                               search, my_Empty_Locale);
73
74         uselocale(my_Locale);
75         //      freelocale(my_Locale);
76         //      freelocale(my_Empty_Locale);
77         free(search);
78 }
79
80 #endif