[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm lonprintout.pm
foxr
foxr at source.lon-capa.org
Tue Dec 27 15:14:33 EST 2011
foxr Tue Dec 27 20:14:33 2011 EDT
Modified files:
/loncom/interface loncommon.pm lonprintout.pm
Log:
Merge language_hyphenation into trunk.
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1047 loncom/interface/loncommon.pm:1.1048
--- loncom/interface/loncommon.pm:1.1047 Sun Dec 25 20:41:53 2011
+++ loncom/interface/loncommon.pm Tue Dec 27 20:14:32 2011
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1047 2011/12/25 20:41:53 raeburn Exp $
+# $Id: loncommon.pm,v 1.1048 2011/12/27 20:14:32 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -154,6 +154,8 @@
# ----------------------------------------------- Filetypes/Languages/Copyright
my %language;
my %supported_language;
+my %latex_language; # For choosing hyphenation in <transl..>
+my %latex_language_bykey; # for choosing hyphenation from metadata
my %cprtag;
my %scprtag;
my %fe; my %fd; my %fm;
@@ -186,11 +188,15 @@
while (my $line = <$fh>) {
next if ($line=~/^\#/);
chomp($line);
- my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
+ my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
$language{$key}=$val.' - '.$enc;
if ($sup) {
$supported_language{$key}=$sup;
}
+ if ($latex) {
+ $latex_language_bykey{$key} = $latex;
+ $latex_language{$two} = $latex;
+ }
}
close($fh);
}
@@ -3227,11 +3233,29 @@
($supported_language{$code}?' ('.&mt('interface available').')':'');
}
+=pod
+
+=item * &plainlanguagedescription
+
+Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
+and the language character encoding (e.g. ISO) separated by a ' - ' string.
+
+=cut
+
sub plainlanguagedescription {
my $code=shift;
return $language{$code};
}
+=pod
+
+=item * &supportedlanguagecode
+
+Returns the supported language code (e.g. sptutf maps to pt) given a language
+code.
+
+=cut
+
sub supportedlanguagecode {
my $code=shift;
return $supported_language{$code};
@@ -3239,6 +3263,35 @@
=pod
+=item * &latexlanguage()
+
+Given a language key code returns the correspondnig language to use
+to select the correct hyphenation on LaTeX printouts. This is undef if there
+is no supported hyphenation for the language code.
+
+=cut
+
+sub latexlanguage {
+ my $code = shift;
+ return $latex_language{$code};
+}
+
+=pod
+
+=item * &latexhyphenation()
+
+Same as above but what's supplied is the language as it might be stored
+in the metadata.
+
+=cut
+
+sub latexhyphenation {
+ my $key = shift;
+ return $latex_language_bykey{$key};
+}
+
+=pod
+
=item * ©rightids()
returns list of all copyrights
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.611 loncom/interface/lonprintout.pm:1.612
--- loncom/interface/lonprintout.pm:1.611 Wed Dec 21 21:25:40 2011
+++ loncom/interface/lonprintout.pm Tue Dec 27 20:14:33 2011
@@ -1,8 +1,7 @@
-
# The LearningOnline Network
# Printout
#
-# $Id: lonprintout.pm,v 1.611 2011/12/21 21:25:40 www Exp $
+# $Id: lonprintout.pm,v 1.612 2011/12/27 20:14:33 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -41,6 +40,7 @@
use Apache::lonenc;
use Apache::entities;
use Apache::londefdef;
+# use Apache::structurelags; # for language management.
use File::Basename;
@@ -660,7 +660,29 @@
}
-
+##
+# Collect the various \select_language{language_name}
+# latex tags to build a \usepackage[lang-list]{babel} which will
+# appear just prior to the \begin{document} at the front of the concatenated
+# set of resources:
+# @param doc - The string of latex to search/replace.
+# @return string
+# @retval - the modified document stringt.
+#
+sub collect_languages {
+ my $doc = shift;
+ my %languages;
+ while ($doc =~ /\\selectlanguage{(\w+)}/mg) {
+ $languages{$1} = 1; # allows us to request each language exactly once.
+ }
+ my @lang_list = (keys(%languages)); # List of unique languages
+ if (scalar @lang_list) {
+ my $babel_header = '\usepackage[' . join(',', @lang_list) .']{babel}'. "\n";
+ $doc =~ s/\\begin{document}/$babel_header\\begin{document}/;
+ }
+ return $doc;
+}
+#-------------------------------------------------------------------
#
# ssi_with_retries- Does the server side include of a resource.
@@ -3122,6 +3144,11 @@
$result = set_font_size($result);
+ # Insert any babel headers required.
+
+ $result = &collect_languages($result);
+
+
#-- writing .tex file in prtspool
my $temp_file;
my $identifier = &Apache::loncommon::get_cgi_id();
More information about the LON-CAPA-cvs
mailing list