--- loncom/localize/lonlocal.pm 2009/10/02 16:59:29 1.60.2.1 +++ loncom/localize/lonlocal.pm 2011/03/28 21:10:41 1.62 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Localization routines # -# $Id: lonlocal.pm,v 1.60.2.1 2009/10/02 16:59:29 raeburn Exp $ +# $Id: lonlocal.pm,v 1.62 2011/03/28 21:10:41 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -242,17 +242,6 @@ sub current_language { } sub preferred_languages { - my $defdom = &Apache::lonnet::default_login_domain(); - foreach my $domtype ($Apache::lonnet::env{'user.domain'},$Apache::lonnet::env{'request.role.domain'},$defdom) { - next if ($domtype eq ''); - if ($domtype eq 'gci') { - return ('gci'); - } elsif ($domtype eq 'gcitest') { - return ('gct'); - } else { - return ('gci'); - } - } my @languages=(); if (($Apache::lonnet::env{'request.role.adv'}) && ($Apache::lonnet::env{'form.languages'})) { @languages=(@languages,split(/\s*(\,|\;|\:)\s*/,$Apache::lonnet::env{'form.languages'})); @@ -273,6 +262,7 @@ sub preferred_languages { push(@languages,@browser); } + my $defdom = &Apache::lonnet::default_login_domain(); foreach my $domtype ($Apache::lonnet::env{'user.domain'},$Apache::lonnet::env{'request.role.domain'},$defdom) { if ($domtype ne '') { my %domdefs = &Apache::lonnet::get_domain_defaults($domtype); @@ -305,13 +295,12 @@ sub get_genlanguages { sub current_encoding { my $default='UTF-8'; -# UTF-8 character encoding needed for the whole LON-CAPA system -# (interface language and homework problem content) -# See Bugzilla 5702 vs. 2189 and 4067 -# if ($Apache::lonnet::env{'browser.os'} eq 'win' && -# $Apache::lonnet::env{'browser.type'} eq 'explorer') { -# $default='ISO-8859-1'; -# } + unless ($Apache::lonnet::env{'browser.unicode'}) { + if ($Apache::lonnet::env{'browser.os'} eq 'win' && + $Apache::lonnet::env{'browser.type'} eq 'explorer') { + $default='ISO-8859-1'; + } + } if ($lh) { my $enc=$lh->maketext('char_encoding'); return ($enc eq 'char_encoding'?$default:$enc); @@ -345,12 +334,17 @@ sub texthash { # ========= Get a handle (do not invoke in vain, leave this to access handlers) sub get_language_handle { - my $r=shift; + my ($r,$chosen) = @_; if ($r) { my $headers=$r->headers_in; $ENV{'HTTP_ACCEPT_LANGUAGE'}=$headers->{'Accept-language'}; } - my @languages=&preferred_languages(); + my @languages; + if ($chosen ne '') { + @languages=($chosen); + } else { + @languages=&preferred_languages(); + } $ENV{'HTTP_ACCEPT_LANGUAGE'}=''; $lh=Apache::localize->get_handle(@languages); $current_language=¤t_language(); @@ -580,6 +574,44 @@ sub mt_escape { $$str_ref =~s/([\[\]])/~$1/g; } +=pod + +=item * choose_language + +choose_language prompts a user to enter a two letter language code via +keyboard when running a script from the command line. Default is en. + +=cut + +sub choose_language { + my %languages = ( + ar => 'Arabic', + de => 'German', + en => 'English', + es => 'Spanish', + fa => 'Persian', + fr => 'French', + he => 'Hebrew', + ja => 'Japanese', + pt => 'Portuguese', + ru => 'Russian', + tr => 'Turkish', + zh => 'Chinese (Simplified)' + ); + my @posslangs = sort(keys(%languages)); + my $langlist = join('|',@posslangs); + my $lang = 'en'; + print 'Language: English (en). Change? ['.$langlist.']? '; + my $langchoice = ; + chomp($langchoice); + $langchoice =~ s/(^\s+|\s+$)//g; + $langchoice = lc($langchoice); + if (defined($languages{$langchoice})) { + $lang = $langchoice; + } + return $lang; +} + 1; __END__