[LON-CAPA-cvs] cvs: loncom /homework structuretags.pm /interface loncommon.pm lonmsg.pm /localize lonlocal.pm

raeburn raeburn@source.lon-capa.org
Fri, 28 Nov 2008 14:37:01 -0000


raeburn		Fri Nov 28 14:37:01 2008 EDT

  Modified files:              
    /loncom/interface	loncommon.pm lonmsg.pm 
    /loncom/localize	lonlocal.pm 
    /loncom/homework	structuretags.pm 
  Log:
  - Moving &preferred_languages() and &get_genlanguages() from loncommon.pm to lonlocal.pm, so they cn be available in cases where lonlocal.pm is used but loncommon.pm is not. 
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.694 loncom/interface/loncommon.pm:1.695
--- loncom/interface/loncommon.pm:1.694	Sat Nov 22 19:08:21 2008
+++ loncom/interface/loncommon.pm	Fri Nov 28 14:36:50 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.694 2008/11/22 19:08:21 tempelho Exp $
+# $Id: loncommon.pm,v 1.695 2008/11/28 14:36:50 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -677,7 +677,7 @@
             if ($id ne '') {
                 my $en_terr = $locale->{'en_territory'};
                 my $native_terr = $locale->{'native_territory'};
-                my @languages = &preferred_languages();
+                my @languages = &Apache::lonlocal::preferred_languages();
                 if (grep(/^en$/,@languages) || !@languages) {
                     if ($en_terr ne '') {
                         $locale_names{$id} = '('.$en_terr.')';
@@ -2998,7 +2998,7 @@
 
 sub display_languages {
     my %languages=();
-    foreach my $lang (&preferred_languages()) {
+    foreach my $lang (&Apache::lonlocal::preferred_languages()) {
 	$languages{$lang}=1;
     }
     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
@@ -3010,59 +3010,9 @@
     return %languages;
 }
 
-sub preferred_languages {
-    my @languages=();
-    if (($env{'request.role.adv'}) && ($env{'form.languages'})) {
-        @languages=(@languages,split(/\s*(\,|\;|\:)\s*/,$env{'form.languages'}));
-    }
-    if ($env{'course.'.$env{'request.course.id'}.'.languages'}) {
-	@languages=(@languages,split(/\s*(\,|\;|\:)\s*/,
-	         $env{'course.'.$env{'request.course.id'}.'.languages'}));
-    }
-
-    if ($env{'environment.languages'}) {
-	@languages=(@languages,
-		    split(/\s*(\,|\;|\:)\s*/,$env{'environment.languages'}));
-    }
-    my $browser=$ENV{'HTTP_ACCEPT_LANGUAGE'};
-    if ($browser) {
-	my @browser = 
-	    map { (split(/\s*;\s*/,$_))[0] } (split(/\s*,\s*/,$browser));
-	push(@languages,@browser);
-    }
-
-    foreach my $domtype ($env{'user.domain'},$env{'request.role.domain'},
-                         $Apache::lonnet::perlvar{'lonDefDomain'}) {
-        if ($domtype ne '') {
-            my %domdefs = &Apache::lonnet::get_domain_defaults($domtype);
-            if ($domdefs{'lang_def'} ne '') {
-                push(@languages,$domdefs{'lang_def'});
-            }
-        }
-    }
-    return &get_genlanguages(@languages);
-}
-
-sub get_genlanguages {
-    my (@languages) = @_;
-# turn "en-ca" into "en-ca,en"
-    my @genlanguages;
-    foreach my $lang (@languages) {
-        unless ($lang=~/\w/) { next; }
-        push(@genlanguages,$lang);
-        if ($lang=~/(\-|\_)/) {
-            push(@genlanguages,(split(/(\-|\_)/,$lang))[0]);
-        }
-    }
-    #uniqueify the languages list
-    my %count;
-    @genlanguages = map { $count{$_}++ == 0 ? $_ : () } @genlanguages;
-    return @genlanguages;
-}
-
 sub languages {
     my ($possible_langs) = @_;
-    my @preferred_langs = &preferred_languages();
+    my @preferred_langs = &Apache::lonlocal::preferred_languages();
     if (!ref($possible_langs)) {
 	if( wantarray ) {
 	    return @preferred_langs;
Index: loncom/interface/lonmsg.pm
diff -u loncom/interface/lonmsg.pm:1.215 loncom/interface/lonmsg.pm:1.216
--- loncom/interface/lonmsg.pm:1.215	Wed Nov 19 17:38:26 2008
+++ loncom/interface/lonmsg.pm	Fri Nov 28 14:36:50 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines for messaging
 #
-# $Id: lonmsg.pm,v 1.215 2008/11/19 17:38:26 jms Exp $
+# $Id: lonmsg.pm,v 1.216 2008/11/28 14:36:50 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1013,7 +1013,7 @@
             }
         }
     }
-    my @languages=&Apache::loncommon::get_genlanguages(@userlangs);
+    my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
     my $user_lh = Apache::localize->get_handle(@languages);
     return $user_lh;
 }
Index: loncom/localize/lonlocal.pm
diff -u loncom/localize/lonlocal.pm:1.51 loncom/localize/lonlocal.pm:1.52
--- loncom/localize/lonlocal.pm:1.51	Mon Nov 24 16:53:16 2008
+++ loncom/localize/lonlocal.pm	Fri Nov 28 14:36:55 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Localization routines
 #
-# $Id: lonlocal.pm,v 1.51 2008/11/24 16:53:16 jms Exp $
+# $Id: lonlocal.pm,v 1.52 2008/11/28 14:36:55 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -233,6 +233,56 @@
     return 'en';
 }
 
+sub preferred_languages {
+    my @languages=();
+    if (($Apache::lonnet::env{'request.role.adv'}) && ($Apache::lonnet::env{'form.languages'})) {
+        @languages=(@languages,split(/\s*(\,|\;|\:)\s*/,$Apache::lonnet::env{'form.languages'}));
+    }
+    if ($Apache::lonnet::env{'course.'.$Apache::lonnet::env{'request.course.id'}.'.languages'}) {
+        @languages=(@languages,split(/\s*(\,|\;|\:)\s*/,
+                 $Apache::lonnet::env{'course.'.$Apache::lonnet::env{'request.course.id'}.'.languages'}));
+    }
+
+    if ($Apache::lonnet::env{'environment.languages'}) {
+        @languages=(@languages,
+                    split(/\s*(\,|\;|\:)\s*/,$Apache::lonnet::env{'environment.languages'}));
+    }
+    my $browser=$ENV{'HTTP_ACCEPT_LANGUAGE'};
+    if ($browser) {
+        my @browser =
+            map { (split(/\s*;\s*/,$_))[0] } (split(/\s*,\s*/,$browser));
+        push(@languages,@browser);
+    }
+
+    foreach my $domtype ($Apache::lonnet::env{'user.domain'},$Apache::lonnet::env{'request.role.domain'},
+                         $Apache::lonnet::perlvar{'lonDefDomain'}) {
+        if ($domtype ne '') {
+            my %domdefs = &Apache::lonnet::get_domain_defaults($domtype);
+            if ($domdefs{'lang_def'} ne '') {
+                push(@languages,$domdefs{'lang_def'});
+            }
+        }
+    }
+    return &get_genlanguages(@languages);
+}
+
+sub get_genlanguages {
+    my (@languages) = @_;
+# turn "en-ca" into "en-ca,en"
+    my @genlanguages;
+    foreach my $lang (@languages) {
+        unless ($lang=~/\w/) { next; }
+        push(@genlanguages,$lang);
+        if ($lang=~/(\-|\_)/) {
+            push(@genlanguages,(split(/(\-|\_)/,$lang))[0]);
+        }
+    }
+    #uniqueify the languages list
+    my %count;
+    @genlanguages = map { $count{$_}++ == 0 ? $_ : () } @genlanguages;
+    return @genlanguages;
+}
+
 # ============================================================== What encoding?
 
 sub current_encoding {
@@ -279,7 +329,7 @@
 	my $headers=$r->headers_in;
 	$ENV{'HTTP_ACCEPT_LANGUAGE'}=$headers->{'Accept-language'};
     }
-    my @languages=&Apache::loncommon::preferred_languages;
+    my @languages=&preferred_languages();
     $ENV{'HTTP_ACCEPT_LANGUAGE'}='';
     $lh=Apache::localize->get_handle(@languages);
     if ($r) {
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.435 loncom/homework/structuretags.pm:1.436
--- loncom/homework/structuretags.pm:1.435	Tue Nov 25 13:16:17 2008
+++ loncom/homework/structuretags.pm	Fri Nov 28 14:37:01 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.435 2008/11/25 13:16:17 jms Exp $
+# $Id: structuretags.pm,v 1.436 2008/11/28 14:37:01 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1331,7 +1331,7 @@
 	$target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
 	my $include = $token->[2]->{'include'};
 	my $exclude = $token->[2]->{'exclude'};
-        my @preferred_languages=&Apache::loncommon::preferred_languages();
+        my @preferred_languages=&Apache::lonlocal::preferred_languages();
 # This should not even happen, since we should at least have the server language
         if (!$preferred_languages[0]) { $preferred_languages[0]='en'; }
 # Now loop over all languages in order of preference