version 1.2, 2003/08/25 19:22:03
|
version 1.3, 2003/09/22 19:07:59
|
Line 733 my~\$renderArgs~=~\{~'cols'~=>~{[}Apache
|
Line 733 my~\$renderArgs~=~\{~'cols'~=>~{[}Apache
|
Viola! That should do it. |
Viola! That should do it. |
|
|
|
|
|
\subsection{Internationalization} |
|
|
|
In order for your handler to be able to submitted to LON-CAPA, we'd |
|
really appreciate it if your handler was already |
|
internationalized. ``Internationalization'' refers to the process of |
|
adding hooks to code to make it easy to ``localize''. ``Localizing'' a |
|
program means taking advantage of those hooks and create a file that |
|
describes to the LON-CAPA web system how to display LON-CAPA in a |
|
language other then English. |
|
|
|
For more complete information about Internationalization and |
|
Localization, please refer to the Internationalization chapter. For |
|
now, suffice it to say we need to wrap the text strings we are using |
|
in the program in calls to the hook subroutine, which will be named |
|
\texttt{\&mt}. |
|
|
|
First, at the top of your handler, near the other \texttt{use} |
|
commands, add \texttt{use Apache::lonlocal;}. |
|
|
|
Second, find where all the strings are in your program and wrap them |
|
in calls to \texttt{\&mt}. I see the following: |
|
|
|
\begin{enumerate} |
|
|
|
\item In the \texttt{bodytag} call, the title: |
|
|
|
\begin{lyxcode} |
|
\$r->print(\&Apache::loncommon::bodytag(\&mt('Tutorial~Handler'),'','')); |
|
|
|
\end{lyxcode} |
|
|
|
\item In the two messages printed out showing the form submissions: |
|
(Of course in this case these are really just debugging messages |
|
we'd remove before actually using this handler. But let's localize |
|
them for practice) |
|
|
|
\begin{lyxcode} |
|
if~(\$ENV{'form.submission'})~{ |
|
|
|
~~~~\$r->print('<p>'.\&mt('Form submitted').'</p>'); |
|
|
|
}~else~{ |
|
|
|
~~~~\$r->print('<p>'.\&mt('No form information submitted.').'</p>'); |
|
|
|
} |
|
|
|
\end{lyxcode} |
|
|
|
Note we do \emph{not} generally want to wrap HTML tags unless we are |
|
absolutely forced to; those are constant across human languages and |
|
would only burder the translators with stuff they should not need to |
|
deal with. |
|
|
|
\item The label of the button we've created: |
|
|
|
\begin{lyxcode} |
|
\$r->print('<input type=\char`\"{}submit\char`\"{} value=\char`\"{}'~. |
|
|
|
~~~~~\&mt('Increment')~.~'\char`\"{}~/></form>'); |
|
|
|
\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} |
\subsection{Complete Code Listing} |
|
|
For your reference, I include the complete code listing for the tutorial |
For your reference, I include the complete code listing for the tutorial |
Line 749 use~Apache::lonnavmaps;
|
Line 834 use~Apache::lonnavmaps;
|
|
|
use~Apache::Constants~qw(:common); |
use~Apache::Constants~qw(:common); |
|
|
|
use~Apache::lonlocal; |
|
|
~ |
~ |
|
|
=pod |
=pod |
Line 833 sub~handler~\{
|
Line 920 sub~handler~\{
|
|
|
~~~~\$r->print('<html><head><title>Tutorial~Page</title></head>'); |
~~~~\$r->print('<html><head><title>Tutorial~Page</title></head>'); |
|
|
~~~~\$r->print(\&Apache::loncommon::bodytag('Tutorial~Handler','','')); |
~~~~\$r->print(\&Apache::loncommon::bodytag(\&mt('Tutorial~Handler'),'','')); |
|
|
|
|
|
|
~~~~if~(\$ENV\{'form.submission'\})~\{ |
~~~~if~(\$ENV\{'form.submission'\})~\{ |
|
|
~~~~~~~~\$r->print('<p>Form~submitted.</p>'); |
~~~~~~~~\$r->print('<p>'~.~\&mt('Form~submitted.')~.'</p>'); |
|
|
~~~~\}~else~\{ |
~~~~\}~else~\{ |
|
|
~~~~~~~~\$r->print('<p>No~form~information~submitted.</p>'); |
~~~~~~~~\$r->print('<p>'~.~\&mt('No~form~information~submitted.')~.~'</p>'); |
|
|
~~~~\} |
~~~~\} |
|
|
Line 901 sub~handler~\{
|
Line 988 sub~handler~\{
|
|
|
|
|
|
|
~~~~\$r->print('<input~type=\char`\"{}submit\char`\"{}~value=\char`\"{}Increment\char`\"{}~/></form>'); |
~~~~\$r->print('<input~type=\char`\"{}submit\char`\"{}~value=\char`\"{}'~. |
|
|
|
~~~~~~~~\&mt('Increment')~.~'\char`\"{}~/></form>'); |
|
|
~~~~\$r->print('</body></html>'); |
~~~~\$r->print('</body></html>'); |
|
|