From: Ricardo J. <ric...@tr...> - 2004-12-10 14:19:49
|
Hi, I need to customize menus for customers, based on their "prefered language" set in their browsers. To test I changed the code from mypage.tcl ( included in TCLHTTPD package ) to present a different header ( menu header ) for each customer using env(LANG) variable, but it seems to take that info ( current language ) from local machine. I mean, the one tclhttpd is running. The menus are beeing changed to the correct "local" language, so msgcat implementation seems to be correct. I need a way to get (LANG) or whatever variable name, that shows the language set at the remote browser, not local machine. What is the trick ? Did someone else achieve this feature ? Thanks Ricardo Jorge |
From: Ricardo J. <ric...@tr...> - 2004-12-09 21:10:58
|
Hi, I need to customize menus for customers, based on their "preffered language" set in their browsers. To test I changed mypage.tcl ( included in TCLHTTPD package ) to present a different header ( menu header ) for each customer using env(LANG) variable, but it seems to take that info ( current language ) from local machine. I mean, the one tclhttpd is running. The menus are beeing changed to the correct "local" language, so msgcat implementation seems to be correct. I need a way to get (LANG) or whatever variable name, that shows the language set at the remote browser, not local machine. What is the trick ? Did someone else achieve this feature ? Thanks Ricardo Jorge |
From: Michael S. <sc...@un...> - 2004-12-11 09:38:48
|
Ricardo Jorge wrote: > Hi, > > I need to customize menus for customers, based on their "preffered > language" set in their browsers. > > To test I changed mypage.tcl ( included in TCLHTTPD package ) to > present a different header ( menu header ) for each customer using > env(LANG) variable, but it seems to take that info ( current language ) > from local machine. I mean, the one tclhttpd is running. > > The menus are beeing changed to the correct "local" language, so msgcat > implementation seems to be correct. > > I need a way to get (LANG) or whatever variable name, that shows the > language set at the remote browser, not local machine. > > What is the trick ? Did someone else achieve this feature ? Thanks > Try this little example: <html> [ Doc_Dynamic package require msgcat # set the locale set old [msgcat::mclocale] msgcat::mcset de "User set language preference" "Der Nutzer hat eine Sprachpräferenz gesetzt" array unset headers array set headers [Httpd_DumpHeaders [Httpd_CurrentSocket]] if {[info exists headers(accept-language)]} { set items [split $headers(accept-language) {,;}] set out "User languages<br>\n" set ll [list] set langs [list] foreach item $items { if {[string match "q=*" $item]} { set weight [string range $item 2 end] lappend langs [list $weight $ll] set ll [list] } else { lappend ll $item } } set langs [lsort -index 0 -real -decreasing $langs] append out "<table>" foreach row $langs { foreach {weight lang} $row { append out "<tr><td>$weight</td><td>$lang</td></tr>\n" } } append out "</table>" # if we want to use msgcat we have to convert the lang into a format useful for # msgcat and use msgcat::mclocale $lang to set it # this simply assumes the browser sends appropriate lang info set prefered [lindex $langs 0 1 0] set mcpref [string map {- _} $prefered] msgcat::mclocale $mcpref # now use msgcat::mc for outputting text append out "<h2>[msgcat::mc "User set language preference"] : $mcpref</h2>" } else { set out "User has set no language preference" } #reset the locale to the old setting msgcat::mclocale $old set out ] </html> Michael |
From: Michael T. <wa...@ko...> - 2004-12-10 15:52:21
|
Hi Ricardo, The http client should be setting a 'Accepted-Languages' header that contains a list of locale settings preferred by the client. Most clients only set one preferred locale, but the http specification allows a client to specify multiple locales, in order of preference. The web server can then iterate through these locales in order of preference to select the first one that is supported. --Mike On Fri, 2004-12-10 at 09:19, Ricardo Jorge wrote: > Hi, > > I need to customize menus for customers, based on their "prefered language" set in their browsers. > > To test I changed the code from mypage.tcl ( included in TCLHTTPD package ) to present a different header ( menu header ) for each customer using > env(LANG) variable, but it seems to take that info ( current language ) from local machine. I mean, the one tclhttpd is running. > > The menus are beeing changed to the correct "local" language, so msgcat implementation seems to be correct. > > I need a way to get (LANG) or whatever variable name, that shows the language set at the remote browser, not local machine. > > What is the trick ? Did someone else achieve this feature ? Thanks > > > Ricardo Jorge > > > > > > > > > > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real users. > Discover which products truly live up to the hype. Start reading now. > http://productguide.itmanagersjournal.com/ > _______________________________________________ > TclHttpd-users mailing list > Tcl...@li... > https://lists.sourceforge.net/lists/listinfo/tclhttpd-users |