* Detect locale from Browser Environment
authorWilfried Göesgens <willi@citadel.org>
Sun, 27 Nov 2005 19:45:49 +0000 (19:45 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sun, 27 Nov 2005 19:45:49 +0000 (19:45 +0000)
webcit/ChangeLog
webcit/Makefile.in
webcit/context_loop.c
webcit/gettext.c [new file with mode: 0644]

index 33b8b930f4eb1e6f64efbe9e9d2e51f756d65655..f2d3cf07cdbffc8c83c704a64da6ee394e9c2e29 100644 (file)
@@ -1,5 +1,11 @@
 $Id$
 
+Sun Nov 27 18:42:15 CET 2005 dothebart
+* Detect locale from Browser Environment
+
+Sun Nov 27 18:42:15 CET 2005 dothebart
+* staticaly bind codeset to utf8.
+
 Wed Nov 23 23:32:04 EST 2005 ajc
 * Placed a mini roomlist in the iconbar.  This is not in its final form.
 
index 63eff9fae1ba59db0a7dd3aa67f5afed386b7672..66283dfe2192db4b9c70580f9d2061cfda11c56c 100644 (file)
@@ -47,7 +47,7 @@ webserver: webserver.o context_loop.o tools.o ical_dezonify.o \
        calendar.o calendar_tools.o calendar_view.o event.o \
        availability.o iconbar.o crypto.o inetconf.o notes.o \
        groupdav_main.o groupdav_get.o groupdav_propfind.o fmt_date.o \
-       groupdav_options.o autocompletion.o \
+       groupdav_options.o autocompletion.o gettext.o\
        groupdav_delete.o groupdav_put.o http_datestring.o setup_wizard.o \
        $(LIBOBJS)
        $(CC) webserver.o context_loop.o tools.o cookie_conversion.o \
@@ -60,6 +60,7 @@ webserver: webserver.o context_loop.o tools.o ical_dezonify.o \
        groupdav_main.o groupdav_get.o groupdav_propfind.o groupdav_delete.o \
        groupdav_options.o autocompletion.o \
        groupdav_put.o http_datestring.o setup_wizard.o fmt_date.o \
+       gettext.o \
        $(LIBOBJS) $(LIBS) $(LDFLAGS) -o webserver
 
 .c.o:
index 6673a4f679e9e20c81c323aa3bb49b9b5a65b707..aa2863895184b461f9a2caefb80adaacfbf90489 100644 (file)
@@ -290,6 +290,10 @@ void context_loop(int sock)
                        if_modified_since = httpdate_to_timestamp(&buf[19]);
                }
 
+               if (!strncasecmp(buf, "Accept-Language: ", 17)) {
+                       httplang_to_locale(&buf[17]);
+               }
+
                /*
                 * Read in the request
                 */
diff --git a/webcit/gettext.c b/webcit/gettext.c
new file mode 100644 (file)
index 0000000..fb31756
--- /dev/null
@@ -0,0 +1,102 @@
+#include "webcit.h"
+#include "webserver.h"
+
+static const char* AvailLang[]=
+       {
+               "de_DE"
+
+
+       };
+
+/* TODO: we skip the language weightening so far. */
+/* Accept-Language: 'de-de,en-us;q=0.7,en;q=0.3' */
+void httplang_to_locale(const char* LocaleString)
+{
+       char *locale="C";
+       char *wanted_locales[10];
+       int i=0;
+       int j=0;
+       size_t len=strlen(LocaleString);
+       int nFound=0;
+       int nAvail=1;
+       char *search=(char*)malloc(len);
+       int done=0;
+       char *mo;
+       char *webcitdir = WEBCITDIR;
+
+       memcpy(search,LocaleString,len);
+       search[len+1]='\0';
+       len=strlen(search);
+       /* the web browser sends '-', we need '_' */
+       for (i=0;i<len; i++)
+               if (search[i]=='-') search[i]='_';
+       i=0;
+       while ((search[i]!='\0')&&
+                  !done &&
+                  (nFound<10))
+               {
+                       if ((search[i]==',')||(search[i]==';'))
+               
+                               {
+                                       if (search[i]==';') done=1;
+                                       search[i]='\0';
+                                       wanted_locales[nFound]=(char*)&search[j];
+                                       j=i+1;
+                                       nFound++;
+                               }
+                       
+                       i++;
+               }
+       /* todo: weight  */
+
+       for (i=0; i<=nFound; i++)
+               {
+                       for (j=0;j<nAvail; j++)
+                               {
+                                       int ret=strncasecmp(wanted_locales[i],
+                                                                               AvailLang[j],
+                                                                               strlen(wanted_locales[i]));
+                                       if (!ret)
+                                               {
+                                                       locale=AvailLang[j];//wanted_locales[i];
+                                                       i=nFound+1;
+                                                       j=nAvail+1;
+                                                       continue;
+                                               }
+
+                               }
+               }
+       setlocale(LC_ALL,"C");
+       len=strlen(locale);
+       memcpy(search,locale,len);
+       memcpy(&search[len],".UTF8",5);
+       search[len+5]='\0';
+       /*
+       len=strlen(search);
+       mo=malloc(len+1);
+       memcpy(mo,search,len+1);
+       */
+       /*
+       mo = malloc(strlen(webcitdir) + 20);
+       sprintf(mo, "%s/locale", webcitdir);
+
+       lprintf(9, "Message catalog directory: %s\n",
+               bindtextdomain("webcit", mo)
+               );
+       free(mo);
+       
+       lprintf(9, "Text domain: %s\n",
+               textdomain("webcit")
+               );
+       
+       lprintf(9, "Text domain Charset: %s\n",
+                       bind_textdomain_codeset("webcit","UTF8")
+                       );
+       
+       */
+       //setlocale(LC_MESSAGES,mo);//search);
+       setlocale(LC_MESSAGES,search);
+       //      free(mo);
+       free(search);
+
+}