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

www lon-capa-cvs@mail.lon-capa.org
Sat, 03 May 2003 20:35:44 -0000


www		Sat May  3 16:35:44 2003 EDT

  Modified files:              
    /loncom/homework	structuretags.pm 
    /loncom/interface	loncommon.pm 
  Log:
  <languageblock>-tag for multilingual resources, needed for PGL this summer.
  
  Works like this:
  
  This is always shown.
  <languageblock exclude="german,swiss,french">
  Do you speak English?
  </languageblock>
  <languageblock include="german,swiss">
  Sprechen Sie Deutsch?
  </languageblock>
  <languageblock include="french,swiss">
  Parlez-vous francais?
  </languageblock>
  
  Gets language from user environment ("environment.languages") or 
  from the query string 
  
   "foo.html?displaylanguage="swiss"
  
  via function loncommon::display_language
  
  Still need to define "vocabulary" for languages ("displaylanguage=german" or 
  "displaylanguage=deutsch" ???), include in languages.tab,
  but make independent of character set used.
  
  
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.166 loncom/homework/structuretags.pm:1.167
--- loncom/homework/structuretags.pm:1.166	Mon Apr 21 16:59:02 2003
+++ loncom/homework/structuretags.pm	Sat May  3 16:35:43 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.166 2003/04/21 20:59:02 albertel Exp $
+# $Id: structuretags.pm,v 1.167 2003/05/03 20:35:43 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -38,7 +38,7 @@
 use Apache::lonmenu;
 
 BEGIN {
-    &Apache::lonxml::register('Apache::structuretags',('block','while','randomlist','problem','library','web','tex','part','preduedate','postanswerdate','solved','notsolved','startouttext','endouttext'));
+    &Apache::lonxml::register('Apache::structuretags',('block','languageblock','while','randomlist','problem','library','web','tex','part','preduedate','postanswerdate','solved','notsolved','startouttext','endouttext'));
 }
 
 sub start_web {
@@ -600,6 +600,59 @@
 }
 
 sub end_block {
+    my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+    my $result;
+    if ($target eq "edit") {
+	$result.= &Apache::edit::tag_end($target,$token,'');
+    }
+    return $result;
+}
+
+sub start_languageblock {
+    my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+
+    my $result;
+
+    if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
+	$target eq 'tex' || $target eq 'analyze') {
+	my $include = $token->[2]->{'include'};
+	my $exclude = $token->[2]->{'exclude'};
+        my %languages=&Apache::loncommon::display_languages();
+        $result='1';
+	if ($include) {
+            $result='';
+            foreach (split(/\,/,$include)) {
+                if ($languages{$_}) { $result='1'; }
+            }
+	}
+        if ($exclude) {
+            foreach (split(/\,/,$exclude)) {
+                if ($languages{$_}) { $result='0'; }
+            }
+	}
+	if ( ! $result ) {
+	    my $skip=&Apache::lonxml::get_all_text("/languageblock",$parser);
+	    &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
+	}
+	$result='';
+    } elsif ($target eq 'edit') {
+	$result .=&Apache::edit::tag_start($target,$token);
+	$result .=&Apache::edit::text_arg('Include Language:','include',
+					  $token,40);
+	$result .=&Apache::edit::text_arg('Exclude Language:','exclude',
+					  $token,40);
+	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
+    } elsif ($target eq 'modified') {
+	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
+						     $safeeval,'include')
+                        .&Apache::edit::get_new_args($token,$parstack,
+						     $safeeval,'exclude');
+	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
+    }
+    return $result;
+}
+
+sub end_languageblock {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
     my $result;
     if ($target eq "edit") {
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.96 loncom/interface/loncommon.pm:1.97
--- loncom/interface/loncommon.pm:1.96	Sat Apr 19 11:34:06 2003
+++ loncom/interface/loncommon.pm	Sat May  3 16:35:43 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.96 2003/04/19 15:34:06 www Exp $
+# $Id: loncommon.pm,v 1.97 2003/05/03 20:35:43 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1345,6 +1345,26 @@
 # -------------------------------------------------------- Language Description
 sub languagedescription {
     return $language{shift(@_)};
+}
+
+# ----------------------------------------------------------- Display Languages
+# returns a hash with all desired display languages
+#
+
+sub display_languages {
+    my %languages=();
+    if ($ENV{'environment.languages'}) {
+	foreach (split(/\s*(\,|\;|\:)\s*/,$ENV{'environment.languages'})) {
+	    $languages{$_}=1;
+        }
+    }
+    &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
+    if ($ENV{'form.displaylanguage'}) {
+	foreach (split(/\s*(\,|\;|\:)\s*/,$ENV{'form.displaylanguage'})) {
+	    $languages{$_}=1;
+        }
+    }
+    return %languages;
 }
 
 # --------------------------------------------------------------- Copyright IDs