Skip to content
Snippets Groups Projects
Commit 811f39e7 authored by rtoy's avatar rtoy
Browse files

Update localization chapter with new functions. Change example to

show how to use the new functions to enable recording of translatable
strings.
parent 3d45c38b
No related branches found
No related tags found
No related merge requests found
...@@ -2887,19 +2887,21 @@ ends at the end of each line. ...@@ -2887,19 +2887,21 @@ ends at the end of each line.
\subsection{Example Usage} \subsection{Example Usage}
\label{sec:localization-usage} \label{sec:localization-usage}
Here is a simple example of how to localize your code. This assumes Here is a simple example of how to localize your code. Let the file
that you've installed the reader macros via \code{intl::install}. \code{intl-ex.lisp} contain:
\begin{example} \begin{example}
(intl:textdomain "example") (intl:textdomain "example")
(defun foo (x y) (defun foo (x y)
_N"Cool function foo of x and y" "Cool function foo of x and y"
(let ((result (bar x y))) (let ((result (bar x y)))
;; TRANSLATORS: One line comment about bar.
(format t _"bar of ~A and ~A = ~A~%" x y result) (format t _"bar of ~A and ~A = ~A~%" x y result)
;; TRANSLATORS: Do the right thing here. #| TRANSLATORS: Multiline comment about
;; TRANSLATORS: Whatever that might be. how many Xs there are
|#
(format t (intl:ngettext "There is one X" (format t (intl:ngettext "There is one X"
"There are many Xs" "There are many Xs"
x)) x))
...@@ -2909,19 +2911,33 @@ that you've installed the reader macros via \code{intl::install}. ...@@ -2909,19 +2911,33 @@ that you've installed the reader macros via \code{intl::install}.
The call to \code{textdomain} sets the default domain for all The call to \code{textdomain} sets the default domain for all
translatable strings following the call. translatable strings following the call.
When this file is compiled, all of the translatable strings are Here is a sample session for creating a template file:
recorded. This includes the docstring for \code{foo}, the string for
the first \code{format}, and the string marked by the call to
\code{intl:ngettext}.
After all of the files have been compiled, we can dump the recorded
strings. In this case,
\begin{example} \begin{example}
* (intl::dump-pot-files :output-directory "dir/") * (intl:install)
T
* (intl:translation-enable)
T
* (compile-file "intl-ex")
#P"/Volumes/share/cmucl/cvs/intl-ex.sse2f"
NIL
NIL
* (intl::dump-pot-files :output-directory "./")
Dumping 3 messages for domain "example" Dumping 3 messages for domain "example"
NIL NIL
*
\end{example} \end{example}
will create a file named ``example.pot'' in the directory ``dir/''.
When this file is compiled, all of the translatable strings are
recorded. This includes the docstring for \code{foo}, the string for
the first \code{format}, and the string marked by the call to
\code{intl:ngettext}.
A file named ``example.pot'' in the directory ``./'' is created.
The contents of this file are: The contents of this file are:
\begin{example} \begin{example}
#@ example #@ example
...@@ -2941,16 +2957,18 @@ msgstr "" ...@@ -2941,16 +2957,18 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8" "Content-Type: text/plain; charset=UTF-8"
"Content-Transfer-Encoding: 8bit" "Content-Transfer-Encoding: 8bit"
#: /tmp/foo.lisp #. One line comment about bar.
msgid "Cool function foo of x and y" #: intl-ex.lisp
msgid "bar of ~A and ~A = ~A~%"
msgstr "" msgstr ""
#. Whatever that might be. #. Multiline comment about
#: /tmp/foo.lisp how many Xs there are
msgid "bar of ~A and ~A = ~A~%" #: intl-ex.lisp
msgid "Cool function foo of x and y"
msgstr "" msgstr ""
#: /tmp/foo.lisp #: intl-ex.lisp
msgid "There is one X" msgid "There is one X"
msgid_plural "There are many Xs" msgid_plural "There are many Xs"
msgstr[0] "" msgstr[0] ""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment