[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm
foxr
foxr at source.lon-capa.org
Mon Aug 6 07:09:11 EDT 2012
foxr Mon Aug 6 11:09:11 2012 EDT
Modified files:
/loncom/interface loncommon.pm
Log:
BZ838 - add list_languages - provide iso code, description array for
use e.g. in &Apache::edit::select_arg for language selection.
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1087 loncom/interface/loncommon.pm:1.1088
--- loncom/interface/loncommon.pm:1.1087 Sat Jul 21 22:10:23 2012
+++ loncom/interface/loncommon.pm Mon Aug 6 11:09:10 2012
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1087 2012/07/21 22:10:23 raeburn Exp $
+# $Id: loncommon.pm,v 1.1088 2012/08/06 11:09:10 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -154,6 +154,7 @@
# ----------------------------------------------- Filetypes/Languages/Copyright
my %language;
my %supported_language;
+my %supported_codes;
my %latex_language; # For choosing hyphenation in <transl..>
my %latex_language_bykey; # for choosing hyphenation from metadata
my %cprtag;
@@ -188,14 +189,15 @@
while (my $line = <$fh>) {
next if ($line=~/^\#/);
chomp($line);
- my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
+ my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
$language{$key}=$val.' - '.$enc;
if ($sup) {
$supported_language{$key}=$sup;
+ $supported_codes{$key} = $code;
}
if ($latex) {
$latex_language_bykey{$key} = $latex;
- $latex_language{$two} = $latex;
+ $latex_language{$code} = $latex;
}
}
close($fh);
@@ -657,7 +659,7 @@
var n = 0;
if (arguments.length > 0) {
n = Number(arguments[1]);
- if (n !== n) { // shortcut for verifying if it's NaN
+ if (n !== n) { // shortcut for verifying if it is NaN
n = 0;
} else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
n = (n > 0 || -1) * Math.floor(Math.abs(n));
@@ -995,6 +997,34 @@
=pod
+
+=item * &list_languages()
+
+Returns an array reference that is suitable for use in language prompters.
+Each array element is itself a two element array. The first element
+is the language code. The second element a descsriptiuon of the
+language itself. This is suitable for use in e.g.
+&Apache::edit::select_arg (once dereferenced that is).
+
+=cut
+
+sub list_languages {
+ my @lang_choices;
+
+ foreach my $id (&languageids()) {
+ my $code = &supportedlanguagecode($id);
+ if ($code) {
+ my $selector = $supported_codes{$id};
+ my $description = &plainlanguagedescription($id);
+ &Apache::lonnet::logthis("pushing $selector : $description");
+ push (@lang_choices, [$selector, $description]);
+ }
+ }
+ return \@lang_choices;
+}
+
+=pod
+
=item * &linked_select_forms(...)
linked_select_forms returns a string containing a <script></script> block
More information about the LON-CAPA-cvs
mailing list