validator/httpd/cgi-bin check,1.476,1.477

Update of /sources/public/validator/httpd/cgi-bin
In directory hutz:/tmp/cvs-serv24838/httpd/cgi-bin

Modified Files:
	check 
Log Message:
first pass at implementing language negotiation/selection. Can certainly be improved, but it works

Index: check
===================================================================
RCS file: /sources/public/validator/httpd/cgi-bin/check,v
retrieving revision 1.476
retrieving revision 1.477
diff -u -d -r1.476 -r1.477
--- check	12 Mar 2007 20:38:42 -0000	1.476
+++ check	14 Mar 2007 06:33:35 -0000	1.477
@@ -259,11 +259,44 @@
 $File->{Warnings}   = []; # Warnings...
 $File->{Namespaces} = []; # Other (non-root) Namespaces.
 
+#########################################
+# Populate $File->{Opt} -- CGI Options. #
+#########################################
+
+#
+# Preprocess the CGI parameters.
+$q = &prepCGI($File, $q);
+
+
+
 ###############################################################################
 #### Generate Template for Result. ############################################
 ###############################################################################
 
-my $lang = 'en_US'; # @@TODO: conneg;
+# first we determine the chosen language based on
+# 1) lang argument given as parameter (if this language is available)
+# 2) HTTP language negotiation between variants available and user-agent choices
+# 3) English by default
+my $lang         = $q->param('lang')  ? $q->param('lang')    : '';
+my @localizations;
+my $lang_ok = FALSE;
+foreach my $lang_available ( split(" ", $CFG->{Languages}) ) {
+        if ($lang eq $lang_available){ $lang_ok = TRUE; next }
+}
+
+if (($lang eq '') or (!$lang_ok)) { # use HTTP-based negotiation
+    $lang = '';
+    use HTTP::Negotiate qw(choose);
+    foreach my $lang_available ( split(" ", $CFG->{Languages}) ) {
+            push @localizations, [$lang_available, 1.000, 'text/html',   undef,   'utf-8',  $lang_available , undef]
+    }   
+    $lang  = choose(\@localizations);
+}
+
+
+if ($lang eq "en") {
+ $lang = 'en_US'; # legacy
+}
 
 my $T = HTML::Template->new(
   filename          => File::Spec->catfile($CFG->{Paths}->{Templates},
@@ -348,13 +381,9 @@
 
 undef $lang;
 
-#########################################
-# Populate $File->{Opt} -- CGI Options. #
-#########################################
-
-#
-# Preprocess the CGI parameters.
-$q = &prepCGI($File, $q);
+#####################################################
+# Populate $File->{Opt} -- CGI Options. (continued) #
+#####################################################
 
 #
 # Set session switches.

Received on Wednesday, 14 March 2007 06:33:52 UTC