[GRASS-dev] [GRASS GIS] #2425: Import translation function instead of using a buildin

GRASS GIS trac at osgeo.org
Wed Sep 17 15:02:12 PDT 2014


#2425: Import translation function instead of using a buildin
-----------------------------------------------------+----------------------
 Reporter:  wenzeslaus                               |       Owner:  grass-dev@…              
     Type:  task                                     |      Status:  new                      
 Priority:  normal                                   |   Milestone:  7.1.0                    
Component:  Translations                             |     Version:  svn-releasebranch70      
 Keywords:  python, underscore, _, gettext, doctest  |    Platform:  All                      
      Cpu:  Unspecified                              |  
-----------------------------------------------------+----------------------

Comment(by wenzeslaus):

 Replying to [comment:1 glynn]:
 > Replying to [ticket:2425 wenzeslaus]:
 >
 > > Basically, it is necessary to remove all occurrences of:
 > >
 > {{{
 > gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"),
 'locale'), unicode = True)
 > }}}
 > >
 > > By one code based on this line in some module:
 > >
 > {{{
 > _ = gettext.translation('grasswxpy', os.path.join(os.getenv("GISBASE"),
 'locale')).ugettext
 > }}}
 >
 > I'd suggest that what's actually "necessary" is to fix whatever can't
 cope with "_" being a built-in function.

 That's a good point but both doctest and gettext are part of Python and
 they are still not compatible. I would say that they don't want to change
 it. The issue is known for a long time and by a lot of people:
  * https://mail.python.org/pipermail/python-list/2004-February/248035.html
 ([http://bytes.com/topic/python/answers/28870-problem-mixing-doctest-
 gettext-_ other part of discussion]
  * http://sheep.art.pl/Gettext%20and%20Doctest%20Together%20in%20Python
  * https://github.com/nose-devs/nose/issues/393
  * (however, no
 [http://bugs.python.org/issue?@filter=status&@filter=components&components=4&status=1&@columns=id,activity,title,status&@sort=-activity
 Python issue] found)

 A lot of people/projects went the way of using explicit import (rather
 then (implicit) buildin), most notably Django (although I'm aware of some
 recent strange Django decisions):
  * https://docs.djangoproject.com/en/dev/topics/i18n/translation/

 > It shouldn't be necessary to explicitly import "_" into each and every
 file. This is why Python has a (mutable) built-in namespace.

 Yes, that's true, Python allows that but I don't think that it is a good
 practice. Of course, gettext is a bit special but this does not mean that
 it will save it from the risks of using buildin (doctest is probably using
 the buildin for the very same reason, it considers itself special).

 The other motivation is that wxGUI needed some change (since the former
 state was not working) and the only two solutions we found were putting
 `install` call to each file (which is agiast buildin and gettext
 documentation) or using explicit imports.

 I think we should you the same practice everywhere but what remained me
 about this issue was that I have seen in some Python editor an error
 message which was saying that `_(...)` does not take any arguments (or
 something like that, I was not able to get or reproduce the message). This
 is the kind of message is the same as given by doctest, so I guess
 explicit imports would solve both issues.

 The number of imports is high for most of the files (with the exception of
 simple scripts), so I don't consider this as a huge issue.

 We should decide this some day. I wouldn’t do the change for 7.0, but for
 trunk/7.1 it should be safe.

-- 
Ticket URL: <http://trac.osgeo.org/grass/ticket/2425#comment:2>
GRASS GIS <http://grass.osgeo.org>



More information about the grass-dev mailing list