[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm

albertel lon-capa-cvs-allow@mail.lon-capa.org
Tue, 11 Sep 2007 20:40:25 -0000


albertel		Tue Sep 11 16:40:25 2007 EDT

  Modified files:              
    /loncom/interface	loncommon.pm 
  Log:
  - remove duplication from language list
  - accept more than two language possibilities from the browser
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.582 loncom/interface/loncommon.pm:1.583
--- loncom/interface/loncommon.pm:1.582	Tue Sep 11 16:36:30 2007
+++ loncom/interface/loncommon.pm	Tue Sep 11 16:40:23 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.582 2007/09/11 20:36:30 albertel Exp $
+# $Id: loncommon.pm,v 1.583 2007/09/11 20:40:23 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2531,9 +2531,11 @@
 	@languages=(@languages,
 		    split(/\s*(\,|\;|\:)\s*/,$env{'environment.languages'}));
     }
-    my $browser=(split(/\;/,$ENV{'HTTP_ACCEPT_LANGUAGE'}))[0];
+    my $browser=$ENV{'HTTP_ACCEPT_LANGUAGE'};
     if ($browser) {
-	@languages=(@languages,split(/\s*(\,|\;|\:)\s*/,$browser));
+	my @browser = 
+	    map { (split(/\s*;\s*/,$_))[0] } (split(/\s*,\s*/,$browser));
+	push(@languages,@browser);
     }
     if (&Apache::lonnet::domain($env{'user.domain'},'lang_def')) {
 	@languages=(@languages,
@@ -2555,11 +2557,14 @@
     my @genlanguages;
     foreach my $lang (@languages) {
 	unless ($lang=~/\w/) { next; }
-	push (@genlanguages,$lang);
+	push(@genlanguages,$lang);
 	if ($lang=~/(\-|\_)/) {
 	    push(@genlanguages,(split(/(\-|\_)/,$lang))[0]);
 	}
     }
+    #uniqueify the languages list
+    my %count;
+    @genlanguages = map { $count{$_}++ == 0 ? $_ : () } @genlanguages;
     return @genlanguages;
 }