--- loncom/html/adm/help/tex/Developer_Tutorial.tex 2003/08/25 19:22:03 1.2 +++ loncom/html/adm/help/tex/Developer_Tutorial.tex 2003/09/22 19:07:59 1.3 @@ -733,6 +733,91 @@ my~\$renderArgs~=~\{~'cols'~=>~{[}Apache 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('

'.\&mt('Form submitted').'

'); + +}~else~{ + +~~~~\$r->print('

'.\&mt('No form information submitted.').'

'); + +} + +\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(''); + +\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 +834,8 @@ use~Apache::lonnavmaps; use~Apache::Constants~qw(:common); +use~Apache::lonlocal; + ~ =pod @@ -833,17 +920,17 @@ sub~handler~\{ ~~~~\$r->print('Tutorial~Page'); -~~~~\$r->print(\&Apache::loncommon::bodytag('Tutorial~Handler','','')); +~~~~\$r->print(\&Apache::loncommon::bodytag(\&mt('Tutorial~Handler'),'','')); ~~~~if~(\$ENV\{'form.submission'\})~\{ -~~~~~~~~\$r->print('

Form~submitted.

'); +~~~~~~~~\$r->print('

'~.~\&mt('Form~submitted.')~.'

'); ~~~~\}~else~\{ -~~~~~~~~\$r->print('

No~form~information~submitted.

'); +~~~~~~~~\$r->print('

'~.~\&mt('No~form~information~submitted.')~.~'

'); ~~~~\} @@ -901,7 +988,9 @@ sub~handler~\{ -~~~~\$r->print(''); +~~~~\$r->print(''); ~~~~\$r->print('');