From 20a2e64d9f1dfbb5c9922d7aae188bec39fba3a3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Sun, 27 Nov 2005 19:45:49 +0000 Subject: [PATCH] * Detect locale from Browser Environment --- webcit/ChangeLog | 6 +++ webcit/Makefile.in | 3 +- webcit/context_loop.c | 4 ++ webcit/gettext.c | 102 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 webcit/gettext.c diff --git a/webcit/ChangeLog b/webcit/ChangeLog index 33b8b930f..f2d3cf07c 100644 --- a/webcit/ChangeLog +++ b/webcit/ChangeLog @@ -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. diff --git a/webcit/Makefile.in b/webcit/Makefile.in index 63eff9fae..66283dfe2 100644 --- a/webcit/Makefile.in +++ b/webcit/Makefile.in @@ -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: diff --git a/webcit/context_loop.c b/webcit/context_loop.c index 6673a4f67..aa2863895 100644 --- a/webcit/context_loop.c +++ b/webcit/context_loop.c @@ -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 index 000000000..fb31756a9 --- /dev/null +++ b/webcit/gettext.c @@ -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