[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm /xml lonxml.pm
albertel
lon-capa-cvs-allow@mail.lon-capa.org
Tue, 11 Sep 2007 20:36:31 -0000
albertel Tue Sep 11 16:36:31 2007 EDT
Modified files:
/loncom/xml lonxml.pm
/loncom/interface loncommon.pm
Log:
- BUG#4816, implement new &languages() routine for authoring
Index: loncom/xml/lonxml.pm
diff -u loncom/xml/lonxml.pm:1.457 loncom/xml/lonxml.pm:1.458
--- loncom/xml/lonxml.pm:1.457 Mon Sep 10 16:09:13 2007
+++ loncom/xml/lonxml.pm Tue Sep 11 16:36:18 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# XML Parser Module
#
-# $Id: lonxml.pm,v 1.457 2007/09/10 20:09:13 albertel Exp $
+# $Id: lonxml.pm,v 1.458 2007/09/11 20:36:18 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -800,6 +800,7 @@
$safehole->wrap(\&Math::Random::random_set_seed_from_phrase,$safeeval,'&random_set_seed_from_phrase');
$safehole->wrap(\&Math::Random::random_get_seed,$safeeval,'&random_get_seed');
$safehole->wrap(\&Math::Random::random_set_seed,$safeeval,'&random_set_seed');
+ $safehole->wrap(\&Apache::loncommon::languages,$safeeval,'&languages');
$safehole->wrap(\&Apache::lonxml::error,$safeeval,'&LONCAPA_INTERNAL_ERROR');
$safehole->wrap(\&Apache::lonxml::debug,$safeeval,'&LONCAPA_INTERNAL_DEBUG');
$safehole->wrap(\&Apache::lonnet::logthis,$safeeval,'&LONCAPA_INTERNAL_LOGTHIS');
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.581 loncom/interface/loncommon.pm:1.582
--- loncom/interface/loncommon.pm:1.581 Mon Sep 10 19:03:38 2007
+++ loncom/interface/loncommon.pm Tue Sep 11 16:36:30 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.581 2007/09/10 23:03:38 albertel Exp $
+# $Id: loncommon.pm,v 1.582 2007/09/11 20:36:30 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2563,6 +2563,29 @@
return @genlanguages;
}
+sub languages {
+ my ($possible_langs) = @_;
+ my @preferred_langs = &preferred_languages();
+ if (!ref($possible_langs)) {
+ if( wantarray ) {
+ return @preferred_langs;
+ } else {
+ return $preferred_langs[0];
+ }
+ }
+ my %possibilities = map { $_ => 1 } (@$possible_langs);
+ my @preferred_possibilities;
+ foreach my $preferred_lang (@preferred_langs) {
+ if (exists($possibilities{$preferred_lang})) {
+ push(@preferred_possibilities, $preferred_lang);
+ }
+ }
+ if( wantarray ) {
+ return @preferred_possibilities;
+ }
+ return $preferred_possibilities[0];
+}
+
###############################################################
## Student Answer Attempts ##
###############################################################