[LON-CAPA-cvs] cvs: loncom /cgi translator.pl /interface lonpreferences.pm /localize lonlocal.pm doc/loncapafiles loncapafiles.lpml

www lon-capa-cvs@mail.lon-capa.org
Tue, 16 Sep 2003 22:40:26 -0000


This is a MIME encoded message

--www1063752026
Content-Type: text/plain

www		Tue Sep 16 18:40:26 2003 EDT

  Added files:                 
    /loncom/cgi	translator.pl 

  Modified files:              
    /doc/loncapafiles	loncapafiles.lpml 
    /loncom/interface	lonpreferences.pm 
    /loncom/localize	lonlocal.pm 
  Log:
  Continued work on Maketext
  * can now set language preferences
  * adv users can set "translator" language, and access little script to
  enter translations for phrases covered by &mt
  
  
--www1063752026
Content-Type: text/plain
Content-Disposition: attachment; filename="www-20030916184026.txt"

Index: doc/loncapafiles/loncapafiles.lpml
diff -u doc/loncapafiles/loncapafiles.lpml:1.283 doc/loncapafiles/loncapafiles.lpml:1.284
--- doc/loncapafiles/loncapafiles.lpml:1.283	Tue Sep 16 15:23:47 2003
+++ doc/loncapafiles/loncapafiles.lpml	Tue Sep 16 18:40:25 2003
@@ -2,7 +2,7 @@
  "http://lpml.sourceforge.net/DTD/lpml.dtd">
 <!-- loncapafiles.lpml -->
 
-<!-- $Id: loncapafiles.lpml,v 1.283 2003/09/16 19:23:47 www Exp $ -->
+<!-- $Id: loncapafiles.lpml,v 1.284 2003/09/16 22:40:25 www Exp $ -->
 
 <!--
 
@@ -873,6 +873,14 @@
 <categoryname>script</categoryname>
 <description>
 utility cgi script to view status of cluster
+</description>
+</file>
+<file>
+<source>loncom/cgi/translator.pl</source>
+<target dist='default'>home/httpd/cgi-bin/translator.pl</target>
+<categoryname>script</categoryname>
+<description>
+utility cgi script to enter translations
 </description>
 </file>
 <file>
Index: loncom/interface/lonpreferences.pm
diff -u loncom/interface/lonpreferences.pm:1.27 loncom/interface/lonpreferences.pm:1.28
--- loncom/interface/lonpreferences.pm:1.27	Thu Aug 28 23:08:18 2003
+++ loncom/interface/lonpreferences.pm	Tue Sep 16 18:40:25 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Preferences
 #
-# $Id: lonpreferences.pm,v 1.27 2003/08/29 03:08:18 bowersj2 Exp $
+# $Id: lonpreferences.pm,v 1.28 2003/09/16 22:40:25 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -101,6 +101,82 @@
 ################################################################
 
 ################################################################
+#         Language Change Subroutines                          #
+################################################################
+sub languagechanger {
+    my $r = shift;
+    my $user       = $ENV{'user.name'};
+    my $domain     = $ENV{'user.domain'};
+    my %userenv = &Apache::lonnet::get
+        ('environment',['language','translator']);
+    my $language=$userenv{'language'};
+    my $translator=$userenv{'translator'};
+    my $bodytag=&Apache::loncommon::bodytag(
+              'Change Your Language Preferences');
+    $r->print(<<ENDLSCREEN);
+<html>
+$bodytag
+
+<form name="server" action="/adm/preferences" method="post">
+<input type="hidden" name="action" value="verify_and_change_languages" />
+<br />Preferred language:
+<input type="text" size="5" value="$language" name="language" />
+ENDLSCREEN
+    if ($ENV{'user.adv'}) {
+	$r->print (<<ENDTRSC);
+<br />Willing to translate for language:
+<input type="text" size="5" value="$translator" name="translator" />
+ENDTRSC
+    }
+    $r->print('<br /><input type="submit" value="Change" /></form></body></html>');
+}
+
+
+sub verify_and_change_languages {
+    my $r = shift;
+    my $user       = $ENV{'user.name'};
+    my $domain     = $ENV{'user.domain'};
+# Screenname
+    my $newlanguage  = $ENV{'form.language'};
+    $newlanguage=~s/[^\-\w]//g;
+    my $message='';
+    if ($newlanguage) {
+        &Apache::lonnet::put('environment',{'language' => $newlanguage});
+        &Apache::lonnet::appenv('environment.language' => $newlanguage);
+        $message='Set new preferred language to '.$newlanguage;
+    } else {
+        &Apache::lonnet::del('environment',['language']);
+        &Apache::lonnet::delenv('environment\.language');
+        $message='Reset preferred language';
+    }
+    if ($ENV{'user.adv'}) {
+	$message.='<br />';
+	my $newtrans  = $ENV{'form.translator'};
+	$newtrans=~s/[^\-\w]//g;
+	if ($newtrans) {
+	    &Apache::lonnet::put('environment',{'translator' => $newtrans});
+	    &Apache::lonnet::appenv('environment.translator' => $newtrans);
+	    $message.='Set translator to '.$newtrans;
+	} else {
+	    &Apache::lonnet::del('environment',['translator']);
+	    &Apache::lonnet::delenv('environment\.translator');
+	    $message.='Reset translator';
+	}
+    }
+
+    my $bodytag=&Apache::loncommon::bodytag(
+                    'Change Your Language Preferences');
+    $r->print(<<ENDVCSCREEN);
+<html>
+$bodytag
+</p>
+$message
+</body></html>
+ENDVCSCREEN
+}
+
+
+################################################################
 #         Anonymous Discussion Name Change Subroutines         #
 ################################################################
 sub screennamechanger {
@@ -657,6 +733,10 @@
         &colorschanger($r);
     } elsif ($ENV{'form.action'} eq 'verify_and_change_colors') {
         &verify_and_change_colors($r);
+    } elsif ($ENV{'form.action'} eq 'changelanguages') {
+        &languagechanger($r);
+    } elsif ($ENV{'form.action'} eq 'verify_and_change_languages') {
+        &verify_and_change_languages($r);
     } elsif ($ENV{'form.action'} eq 'debugtoggle') {
 	if (($ENV{'user.name'} eq 'albertel' ) ||
             ($ENV{'user.name'} eq 'kortemey' ) ||
@@ -714,6 +794,13 @@
 <input type="submit" value="Change color scheme" />
 </form>
 ENDCOLORFORM
+
+	    $r->print(<<ENDLANGUAGES);
+<form name="client" action="/adm/preferences" method="post">
+<input type="hidden" name="action" value="changelanguages" />
+<input type="submit" value="Change language preferences" />
+</form>
+ENDLANGUAGES
 
 	if (($ENV{'user.name'} eq 'albertel' ) ||
             ($ENV{'user.name'} eq 'kortemey' ) ||
Index: loncom/localize/lonlocal.pm
diff -u loncom/localize/lonlocal.pm:1.2 loncom/localize/lonlocal.pm:1.3
--- loncom/localize/lonlocal.pm:1.2	Tue Sep 16 15:23:47 2003
+++ loncom/localize/lonlocal.pm	Tue Sep 16 18:40:25 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Localization routines
 #
-# $Id: lonlocal.pm,v 1.2 2003/09/16 19:23:47 www Exp $
+# $Id: lonlocal.pm,v 1.3 2003/09/16 22:40:25 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -32,6 +32,7 @@
 
 use strict;
 use Apache::localize;
+use Apache::File;
 
 require Exporter;
 
@@ -45,7 +46,16 @@
 # ===================================================== The "MakeText" function
 
 sub mt (@) {
-    return $lh->maketext(@_);
+    unless ($ENV{'environment.translator'}) {
+	return $lh->maketext(@_);
+    } else {
+	return '<a target="trans" href="/cgi-bin/translator.pl?arg1='.
+	    &Apache::lonnet::escape($_[0]).'&arg2='.
+	    &Apache::lonnet::escape($_[1]).'&arg3='.
+	    &Apache::lonnet::escape($_[2]).'&lang='.
+	    $ENV{'environment.translator'}.
+	    '">'.$lh->maketext(@_).'</a>';
+    }
 }
 
 # ========= Get a handle (do not invoke in vain, leave this to access handlers)

Index: loncom/cgi/translator.pl
+++ loncom/cgi/translator.pl
#!/usr/bin/perl
$|=1;
# Generates a html page showing various sataus reports about the cluster
# $Id: translator.pl,v 1.1 2003/09/16 22:40:25 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
use strict;
use GDBM_File;

my $buffer;

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
my @pairs=split(/&/,$buffer);
my $pair; my $name; my $value;

my %FORM=();
my %hash=();

foreach $pair (@pairs) {
    ($name,$value) = split(/=/,$pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
    $FORM{$name}=$value;
} 


$buffer=$ENV{'QUERY_STRING'};
@pairs=split(/&/,$buffer);
foreach $pair (@pairs) {
    ($name,$value) = split(/=/,$pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
    $FORM{$name}=$value;
} 
print 'Content-type: text/html'."\n\n";


    print (<<ENDSCREEN);
<html><body>
<h1>LON-CAPA Localization Project</h1>
<h3>Language: $FORM{'lang'}</h3>
<a href="/cgi-bin/translator.pl?lang=$FORM{'lang'}&list=1">List all</a><br />
ENDSCREEN

$FORM{'lang'}=~s/\W//g;

if ($FORM{'trans'}) {
    if (tie(%hash,'GDBM_File',
	  '/home/httpd/perl/logs/'.$FORM{'lang'}.'.db',&GDBM_WRCREAT(),0640)) {
	$hash{$FORM{'arg1'}}=$FORM{'trans'};
	untie %hash;
	print "Stored.";
    }
} elsif ($FORM{'list'}) {
    if (tie(%hash,'GDBM_File',
	  '/home/httpd/perl/logs/'.$FORM{'lang'}.'.db',&GDBM_READER(),0640)) {
	print "<pre>";
	foreach (sort keys %hash) {
	    print "\n   '".$_."'".
		"\n=> '".$hash{$_}."',\n";
	}
	print "</pre>";
	untie %hash;
    }
} else {
    my $trans=$FORM{'arg1'};
    if (tie(%hash,'GDBM_File',
	  '/home/httpd/perl/logs/'.$FORM{'lang'}.'.db',&GDBM_READER(),0640)) {
	if ($hash{$trans}) { $trans=$hash{$trans}; }
	untie %hash;
    }
    print (<<ENDQUERY);
<blockquote>$FORM{'arg1'}</blockquote>
<form method="post">
<input type="hidden" name="org" value="$FORM{'arg1'}">
<input type="hidden" name="lang" value="$FORM{'lang'}">
<input type="text" size="80" name="trans" value="$trans">
<input type="submit">
</form>
ENDQUERY
}

print('</body></html>');
exit 0;

--www1063752026--