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