[Python-checkins] python/dist/src/Doc/lib libgettext.tex,1.14,1.15

bwarsaw@users.sourceforge.net bwarsaw@users.sourceforge.net
Fri, 11 Apr 2003 11:36:46 -0700


Update of /cvsroot/python/python/dist/src/Doc/lib
In directory sc8-pr-cvs1:/tmp/cvs-serv25282

Modified Files:
	libgettext.tex 
Log Message:
>From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html

- Expose NullTranslations and GNUTranslations to __all__

- Set the default charset to iso-8859-1.  It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter.  Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.

- Add a "coerce" default argument to GNUTranslations's constructor.  The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode.  For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.

The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read. 
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.

Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False.  Most code I suspect will want to set this to True and use
.ugettext().

- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.


Index: libgettext.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/lib/libgettext.tex,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** libgettext.tex	22 Nov 2002 14:28:53 -0000	1.14
--- libgettext.tex	11 Apr 2003 18:36:43 -0000	1.15
***************
*** 286,296 ****
  overrides \method{_parse()} to enable reading GNU \program{gettext}
  format \file{.mo} files in both big-endian and little-endian format.
  
! It also parses optional meta-data out of the translation catalog.  It
! is convention with GNU \program{gettext} to include meta-data as the
! translation for the empty string.  This meta-data is in \rfc{822}-style
! \code{key: value} pairs.  If the key \code{Content-Type} is found,
! then the \code{charset} property is used to initialize the
! ``protected'' \member{_charset} instance variable.  The entire set of
  key/value pairs are placed into a dictionary and set as the
  ``protected'' \member{_info} instance variable.
--- 286,300 ----
  overrides \method{_parse()} to enable reading GNU \program{gettext}
  format \file{.mo} files in both big-endian and little-endian format.
+ It also adds the ability to coerce both message ids and message
+ strings to Unicode.
  
! \class{GNUTranslations} parses optional meta-data out of the
! translation catalog.  It is convention with GNU \program{gettext} to
! include meta-data as the translation for the empty string.  This
! meta-data is in \rfc{822}-style \code{key: value} pairs, and must
! contain the \code{Project-Id-Version}.  If the key
! \code{Content-Type} is found, then the \code{charset} property is used
! to initialize the ``protected'' \member{_charset} instance variable,
! defaulting to \code{iso-8859-1} if not found.  The entire set of
  key/value pairs are placed into a dictionary and set as the
  ``protected'' \member{_info} instance variable.
***************
*** 303,310 ****
  returns a Unicode string by passing both the translated message string
  and the value of the ``protected'' \member{_charset} variable to the
! builtin \function{unicode()} function.
  
  To facilitate plural forms, the methods \method{ngettext} and
  \method{ungettext} are overridden as well.
  
  \subsubsection{Solaris message catalog support}
--- 307,330 ----
  returns a Unicode string by passing both the translated message string
  and the value of the ``protected'' \member{_charset} variable to the
! builtin \function{unicode()} function.  Note that if you use
! \method{ugettext()} you probably also want your message ids to be
! Unicode.  To do this, set the variable \var{coerce} to \code{True} in
! the \class{GNUTranslations} constructor.  This ensures that both the
! message ids and message strings are decoded to Unicode when the file
! is read, using the file's \code{charset} value.  If you do this, you
! will not want to use the \method{gettext()} method -- always use
! \method{ugettext()} instead.
  
  To facilitate plural forms, the methods \method{ngettext} and
  \method{ungettext} are overridden as well.
+ 
+ \begin{methoddesc}[GNUTranslations]{__init__}{
+     \optional{fp\optional{, coerce}}
+ Constructs and parses a translation catalog in GNU gettext format.
+ \var{fp} is passed to the base class (\class{NullTranslations})
+ constructor.  \var{coerce} is a flag specifying whether message ids
+ and message strings should be converted to Unicode when the file is
+ parsed.  It defaults to \code{False} for backward compatibility.
+ \end{methoddesc}
  
  \subsubsection{Solaris message catalog support}