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

GRASS GIS trac at osgeo.org
Tue Sep 16 18:35:24 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                              |  
-----------------------------------------------------+----------------------
 ''Here are my notes about this issue since I was forgetting about it.''

 On some occasions, some of GRASS functions does not work because of
 translation function (`_` - underscore). The problem occurs on some
 strange conditions and when you are using Python
 [https://docs.python.org/2/library/doctest.html doctest] which we are
 using more and more.

 There is already several workarounds in wxGUI and also testing framework
 as
 [wiki:GSoC/2014/TestingFrameworkForGRASS#Findingandrunningthetestmodules
 described here]:
 > `doctests` currently don't work with grass.script unless you call a
 [source:grass/trunk/gui/wxpython/core/toolboxes.py?rev=60218#L630 set of
 functions] to deal with function _ (underscore) because of installing
 translate function as buildin _ function while _ function is used also in
 doctest.

 Grep for function `do_doctest_gettext_workaround` to see definition and
 how it is used.

 I already did this change for wxGUI more then a year ago and it seems to
 work. It was necessary because there was some problem with not translated
 files and this was only way to fix it besides going against documentation.

 For now I don't know how `lib/python`, `scripts`, and `temporal` differs
 in translations, so this should be clarified before changing it.

 See comment:5:ticket:1739 for deep discussion of the topic.

 For wxGUI this was implemented in the r57219 and r57220 as a result of
 #1739 and other investigation.

 This might be a blocker for some solutions of #2142. The new method should
 be flexible allowing to obtain translations from two sources
 simultaneously.

 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
 }}}

 The actual implementation must be more complicated
 (changeset:57220#file0).

 Then each file, depending on the name and placement of translation
 function, must import:
 {{{
 from grass.script.utils import _
 from grass.script.translations import _
 from grass.*.utils import _
 from grass.*.translations import _
 from grass.translations import _
 }}}

 Probably `grass.translations` is the best since in GUI a module inside
 some other package is creating dependencies (changeset:57219#file10,
 changeset:57219#file13).

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



More information about the grass-dev mailing list