[LON-CAPA-cvs] cvs: loncom(language_hyphenation) /interface loncommon.pm lonprintout.pm
foxr
foxr at source.lon-capa.org
Mon Dec 26 08:47:19 EST 2011
foxr Mon Dec 26 13:47:19 2011 EDT
Modified files: (Branch: language_hyphenation)
/loncom/interface loncommon.pm lonprintout.pm
Log:
bz6490 - Support the collection of language selection -> latex/babel language
names in loncommon.pm.
- collect \selectlanguage{babel-names} and produce, if necessary a
\usepackage[language-list]{babel} prior to \begin{document}
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1028 loncom/interface/loncommon.pm:1.1028.2.1
--- loncom/interface/loncommon.pm:1.1028 Mon Nov 14 00:20:34 2011
+++ loncom/interface/loncommon.pm Mon Dec 26 13:47:18 2011
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1028 2011/11/14 00:20:34 raeburn Exp $
+# $Id: loncommon.pm,v 1.1028.2.1 2011/12/26 13:47:18 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -154,6 +154,7 @@
# ----------------------------------------------- Filetypes/Languages/Copyright
my %language;
my %supported_language;
+my %latex_language; # Language name LaTeX uses for selecting hyphenation.
my %cprtag;
my %scprtag;
my %fe; my %fd; my %fm;
@@ -186,11 +187,14 @@
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{$two} = $latex;
+ }
}
close($fh);
}
@@ -3230,11 +3234,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};
@@ -3242,6 +3264,21 @@
=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 * ©rightids()
returns list of all copyrights
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.610 loncom/interface/lonprintout.pm:1.610.2.1
--- loncom/interface/lonprintout.pm:1.610 Tue Nov 29 11:57:33 2011
+++ loncom/interface/lonprintout.pm Mon Dec 26 13:47:18 2011
@@ -1,8 +1,7 @@
-
# The LearningOnline Network
# Printout
#
-# $Id: lonprintout.pm,v 1.610 2011/11/29 11:57:33 foxr Exp $
+# $Id: lonprintout.pm,v 1.610.2.1 2011/12/26 13:47:18 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