--- loncom/html/adm/help/tex/Developer_Tutorial.tex 2003/08/25 19:22:03 1.2 +++ loncom/html/adm/help/tex/Developer_Tutorial.tex 2005/04/07 06:56:22 1.6 @@ -1,3 +1,5 @@ +\label{Developer_Tutorial} + \section{Adding a Handler to LON-CAPA} In this section, we will add a brand new {}``handler'' to LON-CAPA. @@ -33,7 +35,7 @@ for the log files, or make a symlink the \item LON-CAPA must be installed and running. \item \textbf{Perl}: You're going to need to know some or you will not understand the code. You don't need to be intimately familiar with the many hundreds -of libraries Perl has, though, which is much harder then learning +of libraries Perl has, though, which is much harder than learning the language. \item Knowledge of the Apache server is not required for this tutorial, but {}``real work'' may require more information then is given here. @@ -361,7 +363,7 @@ To send back a proper HTTP response, add ~~~~if~(\$r->header\_only)~\{ -~~~~~~~~if~(\$ENV\{'browser.mathml'\})~\{ +~~~~~~~~if~(\$env\{'browser.mathml'\})~\{ ~~~~~~~~~~~~\$r->content\_type('text/xml'); @@ -379,7 +381,7 @@ To send back a proper HTTP response, add ~~~~\#~Send~header,~don't~cache~this~page -~~~~if~(\$ENV\{'browser.mathml'\})~\{ +~~~~if~(\$env\{'browser.mathml'\})~\{ ~~~~~~~~\$r->content\_type('text/xml'); @@ -451,7 +453,7 @@ use~Apache::lonnavmaps; Remove the {}``Hello world!'' line and replace it with this: \begin{lyxcode} -\$ENV\{'form.condition'\}~=~1; +\$env\{'form.condition'\}~=~1; my~\$renderArgs~=~\{~'cols'~=>~{[}Apache::lonnavmaps::resource{]}, @@ -468,11 +470,11 @@ Line by line: contains routines that help render navmaps. For more information, see later in this manual or type \texttt{man Apache::lonnavmaps}. This ensures these routines are loaded into memory. -\item \texttt{\textbf{\$ENV\{'form.condition'\} = 1;}}: This is an an argument +\item \texttt{\textbf{\$env\{'form.condition'\} = 1;}}: This is an an argument being passed to the Apache::lonnavmaps::render routine in a rather unorthodox way. This will cause the navmap to render all of the resources, by default, except for what we explicitly exclude. Since we're not -going to exclude anything (which we would do with \texttt{\$ENV\{'form.filter'\}}), +going to exclude anything (which we would do with \texttt{\$env\{'form.filter'\}}), all resources will be shown. \item \texttt{\textbf{my \$renderArgs\ldots{}\$r\};}}: Since the \texttt{render} routine takes a \emph{lot} of arguments, the \texttt{render} routine @@ -522,7 +524,7 @@ In doing this, we'll learn: The first thing we need to do to accomplish this is to add an HTML form to the screen so we have something to submit. Just above the -\texttt{\$ENV\{'form.condition'\}} line, add the following: +\texttt{\$env\{'form.condition'\}} line, add the following: \begin{lyxcode} \$r->print(\char`\"{}
'); + +\end{lyxcode} + +\end{enumerate} + +Note we only need to wrap things the human user will see; we don't +need to wrap the \texttt{tutorial} parameter to the +\texttt{Apache::lonnet::restore} call, for instance, and in fact wierd +things could happen if we did! Also note that resource names and such +are already as internationalized as they are going to get, so we don't +need to worry about them. + +Since the internationalization system will return the value passed to +\texttt{\&mt} by default if it can't find a translation, it's safe to +internationalize code before translations exist, and in fact it's a +necessary step. + +Also note that punctuation should be wrapped in the \texttt{\&mt} +calls, including things like trailing periods, since not all languages +have the same punctuation standards as English. + +This only covers simple internationalization. This can take you a long +way, but if you encounter a more difficult problem, please send a note +to the \texttt{lon-capa-dev@mail.lon-capa.org} mailing list. + \subsection{Complete Code Listing} For your reference, I include the complete code listing for the tutorial @@ -749,6 +836,8 @@ use~Apache::lonnavmaps; use~Apache::Constants~qw(:common); +use~Apache::lonlocal; + ~ =pod @@ -787,7 +876,7 @@ sub~handler~\{ ~~~~if~(\$r->header\_only)~\{ -~~~~~~~~if~(\$ENV\{'browser.mathml'\})~\{ +~~~~~~~~if~(\$env\{'browser.mathml'\})~\{ ~~~~~~~~~~~~\$r->content\_type('text/xml'); @@ -805,7 +894,7 @@ sub~handler~\{ ~~~~\#~Send~header,~don't~cache~this~page -~~~~if~(\$ENV\{'browser.mathml'\})~\{ +~~~~if~(\$env\{'browser.mathml'\})~\{ ~~~~~~~~\$r->content\_type('text/xml'); @@ -833,17 +922,17 @@ sub~handler~\{ ~~~~\$r->print('Form~submitted.
'); +~~~~~~~~\$r->print(''~.~\&mt('Form~submitted.')~.'
'); ~~~~\}~else~\{ -~~~~~~~~\$r->print('No~form~information~submitted.
'); +~~~~~~~~\$r->print(''~.~\&mt('No~form~information~submitted.')~.~'
'); ~~~~\} @@ -853,7 +942,7 @@ sub~handler~\{ ~~~~my~\%newHash~=~(); -~~~~foreach~(keys~\%ENV)~\{ +~~~~foreach~(keys~\%env)~\{ ~~~~~~~~if~(substr(\$\_,~0,~10)~eq~'form.symb.')~\{ @@ -887,7 +976,7 @@ sub~handler~\{ ~~~~~~~~~~~~~~\char`\"{}name='submission'~value='1'~/>\char`\"{}); -~~~~\$ENV\{'form.condition'\}~=~1; +~~~~\$env\{'form.condition'\}~=~1; ~~~~my~\$renderArgs~=~\{~'cols'~=>~{[}Apache::lonnavmaps::resource, @@ -901,7 +990,9 @@ sub~handler~\{ -~~~~\$r->print(''); +~~~~\$r->print(''); ~~~~\$r->print('