[LON-CAPA-cvs] cvs: loncom /html/adm/help/tex Developer_Tutorial.tex
bowersj2
lon-capa-cvs@mail.lon-capa.org
Mon, 22 Sep 2003 19:07:59 -0000
bowersj2 Mon Sep 22 15:07:59 2003 EDT
Modified files:
/loncom/html/adm/help/tex Developer_Tutorial.tex
Log:
Internationalize the Developer Tutorial, since this seems like one of
those baseline things we'd like all new developers to know.
Index: loncom/html/adm/help/tex/Developer_Tutorial.tex
diff -u loncom/html/adm/help/tex/Developer_Tutorial.tex:1.2 loncom/html/adm/help/tex/Developer_Tutorial.tex:1.3
--- loncom/html/adm/help/tex/Developer_Tutorial.tex:1.2 Mon Aug 25 15:22:03 2003
+++ loncom/html/adm/help/tex/Developer_Tutorial.tex Mon Sep 22 15:07:59 2003
@@ -733,6 +733,91 @@
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}
For your reference, I include the complete code listing for the tutorial
@@ -749,6 +834,8 @@
use~Apache::Constants~qw(:common);
+use~Apache::lonlocal;
+
~
=pod
@@ -833,17 +920,17 @@
~~~~\$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'\})~\{
-~~~~~~~~\$r->print('<p>Form~submitted.</p>');
+~~~~~~~~\$r->print('<p>'~.~\&mt('Form~submitted.')~.'</p>');
~~~~\}~else~\{
-~~~~~~~~\$r->print('<p>No~form~information~submitted.</p>');
+~~~~~~~~\$r->print('<p>'~.~\&mt('No~form~information~submitted.')~.~'</p>');
~~~~\}
@@ -901,7 +988,9 @@
-~~~~\$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>');