validator/httpd/cgi-bin check,1.610,1.611

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

Modified Files:
	check 
Log Message:
Simplify localization selection, pre-process related config in BEGIN.

Index: check
===================================================================
RCS file: /sources/public/validator/httpd/cgi-bin/check,v
retrieving revision 1.610
retrieving revision 1.611
diff -u -d -r1.610 -r1.611
--- check	3 Jan 2009 21:02:28 -0000	1.610
+++ check	3 Jan 2009 21:09:31 -0000	1.611
@@ -57,7 +57,6 @@
 use HTML::Encoding       0.52 qw();
 use HTML::Parser         3.25 qw(); # Need 3.25 for $p->ignore_elements.
 use HTML::Template       2.6  qw();
-use HTTP::Negotiate           qw();
 use HTTP::Request             qw();
 use HTTP::Headers::Auth       qw(); # Needs to be imported after other HTTP::*.
 use SGML::Parser::OpenSP      qw();
@@ -167,6 +166,14 @@
     $CFG->{Protocols}->{Allow} = [split(/\s*,\s*/, $allowed)];
   }
 
+  # Split available languages into a list
+  if (my $langs = delete($CFG->{Languages})) {
+    $CFG->{Languages} = [split(/\s+/, $langs)];
+  } else {
+    # Default to english
+    $CFG->{Languages} = ["en"];
+  }
+
   { # Make types config indexed by FPI.
     my $_types = {};
     map { $_types->{$CFG->{Types}->{$_}->{PubID}} = $CFG->{Types}->{$_} }
@@ -281,37 +288,30 @@
 #### Generate Template for Result. ############################################
 ###############################################################################
 
-# in case there is no language set up on the server, we'll use english as default:
-if (!defined $CFG->{Languages}) {
-  $CFG->{Languages} = "en";
-}
-
 # 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 $lang = $q->param('lang') || '';
 my @localizations;
-my $lang_ok = FALSE;
-foreach my $lang_available (split(" ", $CFG->{Languages})) {
+foreach my $lang_available (@{$CFG->{Languages}}) {
   if ($lang eq $lang_available) {
-    $lang_ok = TRUE;
-    next;
+    # Requested language (from parameters) is available, just use it
+    undef @localizations;
+    last;
   }
+  push @localizations,
+    [$lang_available, 1, 'text/html', undef, 'utf-8', $lang_available, undef];
 }
 
-if (($lang eq '') or (!$lang_ok)) { # use HTTP-based negotiation
-  $lang = '';
-  foreach my $lang_available (split(" ", $CFG->{Languages})) {
-    push @localizations, [$lang_available, 1.000, 'text/html', undef,
-                          'utf-8', $lang_available, undef];
-  }
+# If language is not chosen yet, use HTTP-based negotiation
+if (@localizations) {
+  require HTTP::Negotiate;
   $lang = HTTP::Negotiate::choose(\@localizations);
 }
 
-# HTTP::Negotiate::choose may return undef
-# e.g if sent Accept-Language: en;q=0
-$lang = 'en_US' if (!defined($lang));
+# HTTP::Negotiate::choose may return undef e.g if sent Accept-Language: en;q=0
+$lang ||= 'en_US';
 
 if ($lang eq "en") {
   $lang = 'en_US'; # legacy

Received on Saturday, 3 January 2009 21:09:43 UTC