[PATCH] Do not translate empty strings, gettext translates them into system information (basically PO file header)

Anne Mulhern amulhern at redhat.com
Thu Nov 13 13:26:10 UTC 2014





----- Original Message -----
> From: "Vratislav Podzimek" <vpodzime at redhat.com>
> To: "anaconda patch review" <anaconda-patches at lists.fedorahosted.org>
> Sent: Wednesday, November 12, 2014 8:46:23 AM
> Subject: Re: [PATCH] Do not translate empty strings,	gettext translates them	into system information (basically PO
> file	header)
> 
> On Wed, 2014-11-12 at 08:42 -0500, Anne Mulhern wrote:
> > 
> > 
> > 
> > ----- Original Message -----
> > > From: "Vojtech Trefny" <vtrefny at redhat.com>
> > > To: anaconda-patches at lists.fedorahosted.org
> > > Sent: Wednesday, November 12, 2014 8:06:17 AM
> > > Subject: [PATCH] Do not translate empty strings,	gettext translates them
> > > into system information (basically PO file
> > > 	header)
> > > 
> > > ---
> > >  blivet/i18n.py | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/blivet/i18n.py b/blivet/i18n.py
> > > index 1f07266..2f033bf 100644
> > > --- a/blivet/i18n.py
> > > +++ b/blivet/i18n.py
> > > @@ -45,8 +45,8 @@ N_ = lambda x: x
> > >  # evaluated on every call.
> > >  # pylint: disable=unnecessary-lambda
> > >  if six.PY2:
> > > -    _ = lambda x: _get_translations().ugettext(x)
> > > +    _ = lambda x: _get_translations().ugettext(x) if x else ""
> > >      P_ = lambda x, y, z: _get_translations().ungettext(x, y, z)
> > >  else:
> > > -    _ = lambda x: _get_translations().gettext(x)
> > > +    _ = lambda x: _get_translations().gettext(x) if x else ""
> > >      P_ = lambda x, y, z: _get_translations().ngettext(x, y, z)
> > > --
> > > 2.1.0
> > > 
> > > _______________________________________________
> > > anaconda-patches mailing list
> > > anaconda-patches at lists.fedorahosted.org
> > > https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
> > > 
> > 
> > Can you make these explicitly check whether value to be translated is
> > empty string, as
> > 
> > _ = lambda x: _get_translations().gettext(x) if x == "" else ""
> > 
> > ?
> I think it won't make a difference:
> """""
> In [2]: i18n._(None)
> 
> """""
> 
> so None is translated to "" anyway. Or is there something I'm
> overlooking? If yes, we should change this in pyanaconda/i18n.py too.

Its not entirely clear to me what is being fixed.
Somehow, the result of the gettext() translation of the empty string
causes a problem.

Maybe it makes a header in a *.po file and no corresponding data
which causes a parsing problem?

If the result of the translation of None would cause the same
problem, then definitely it should be avoided as well. But the
commit message should, in that case, not mention only empty
strings.

Currently I see distinct behaviors in master on empty string and None, as:

[mulhern at localhost blivet]$ PYTHONPATH=/home/mulhern/blivet python
Python 2.7.5 (default, Jun 19 2014, 12:16:30) 
[GCC 4.8.2 20131212 (Red Hat 4.8.2-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import blivet
dm.c: 1693: not running as root returning empty list
>>> from blivet import i18n
>>> i18n._("")
u''
>>> i18n._(None)
u'None'

although you do not. This appears to be because I'm operating in a NullTranslation context,
and values just get passed through (but converted to
unicode in the process, by ugettext()).

>>> gettext.NullTranslations().ugettext(None)
u'None'

It looks to me like the Python 2 "" should actually be a u"", to match the type
of the strings that ugettext() returns.

I do think that getting "None" for None is more satisfactory than getting the empty string.

I am uncertain as to whether numeric values, e.g., ints can
be entirely ruled out from translation by the category or some other means.
ugettext is certainly happy to translate them in the NullTranslation context.
If not, the value 0 must also be taken into consideration.

- mulhern

> 
> --
> Vratislav Podzimek
> 
> Anaconda Rider | RHCE | Red Hat, Inc. | Brno - Czech Republic
> 
> 
> _______________________________________________
> anaconda-patches mailing list
> anaconda-patches at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
> 


More information about the anaconda-patches mailing list