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

GRASS GIS trac at osgeo.org
Sat Nov 1 17:03:19 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):

 I still think that not using `_` as a buildin for translations is a good
 idea adopted by other projects such as Django (comment:5:ticket:1739).

 If user is trying something in Python command line (in system terminal, in
 wxGUI or elsewhere), he or she will get strange errors in case the Python
 functions will print some warnings, errors or any translatable text. And
 this is wrong I would say.

 >>> from grass.script.core import run_command
 >>> run_command('g.region', rast_='elevation')
 >>> run_command('g.region', _rast='elevation')
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File ".../etc/python/grass/script/core.py", line 355, in run_command
     ps = start_command(*args, **kwargs)
   File ".../etc/python/grass/script/core.py", line 334, in start_command
     args = make_command(prog, flags, overwrite, quiet, verbose, **options)
   File ".../etc/python/grass/script/core.py", line 283, in make_command
     warning(_("To run the module add underscore at the end"
 TypeError: 'int' object is not callable
 >>> _

 It will work in IPython, however:

 In [1]: from grass.script.core import run_command

 In [2]: run_command('g.region', rast_='elevation')
 Out[2]: 0

 In [3]: run_command('g.region', _rast='elevation')
 WARNING: To run the module add underscore at the end of the option <rast>
          to avoid conflict with Python keywords. Underscore at the
          beginning is depreciated in GRASS GIS 7.0 and will be removed in
          version 7.1.
 Out[3]: 0

 In [4]: _
 Out[4]: <bound method NullTranslations.gettext of
 <gettext.NullTranslations instance at 0x7ff801cc45a8>>

 Anyway, using explicit import of `_` rather then "install" to buildins
 would solve not only doctest and Python interactive interpreter but would
 also satisfy number of code checkers which complain about undefined `_`
 symbol. Moreover, "explicit is better than implicit" is from Zen of Python
 ([http://legacy.python.org/dev/peps/pep-0020/ PEP20]).

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

More information about the grass-dev mailing list