[GRASS-dev] [GRASS GIS] #2912: raster_what() not compliant with localised version of GRASS

#2912: raster_what() not compliant with localised version of GRASS
---------------------------------------------+-------------------------
Reporter: andbal | Owner: grass-dev@…
     Type: defect | Status: new
Priority: major | Milestone: 7.0.4
Component: Python | Version: svn-trunk
Keywords: grass.script python translation | CPU: x86-64
Platform: Linux |
---------------------------------------------+-------------------------
Writing a python script, I found that the {{{grass.script.raster_what()}}}
output dictionary has different keys depending on language used in GRASS.
The following python code:
{{{#!python
point = grass.raster_what('clump', [[x,y]])[0]
print(type(point), point)
}}}
returns (with Italian GRASS):
{{{#!python
<type 'dict'> {'clump': {'color': '143:247:067', 'etichetta': '',
'valore': '1'}}
}}}
Changing language to English, returns:
{{{#!python
<type 'dict'> {'clump': {'color': '151:149:192', 'value': '1', 'label':
''}}
}}}
Changing language to German, returns:
{{{#!python
<type 'dict'> {'clump': {'Farbe': '099:113:108', 'value': '1', 'label':
''}}
}}}
The translation seems to depend on the GRASS localisations and make
impossible access to the dictionary keys in a general way.

Anyway a workaround could be achieved using
{{{grass.script.read_command('r.what')}}} and accessing to the list
values.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2912&gt;
GRASS GIS <https://grass.osgeo.org>

#2912: raster_what() not compliant with localised version of GRASS
---------------------+---------------------------------------------
  Reporter: andbal | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.4
Component: Python | Version: svn-trunk
Resolution: | Keywords: grass.script python translation
       CPU: x86-64 | Platform: Linux
---------------------+---------------------------------------------

Comment (by mlennert):

Replying to [ticket:2912 andbal]:
> Writing a python script, I found that the
{{{grass.script.raster_what()}}} output dictionary has different keys
depending on language used in GRASS.

This comes from line 191 in lib/python/script/raster.py where these labels
are noted as translatable strings. I agree that this is a very bad idea
and that such dictionary keys should not be translatable.

Unless anyone gives a good reason for the contrary, I will change the
vector of labels to non-translatable. This might break existing scripts,
but I think this is necessary.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2912#comment:1&gt;
GRASS GIS <https://grass.osgeo.org>

#2912: raster_what() not compliant with localised version of GRASS
---------------------+---------------------------------------------
  Reporter: andbal | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.4
Component: Python | Version: svn-trunk
Resolution: | Keywords: grass.script python translation
       CPU: x86-64 | Platform: Linux
---------------------+---------------------------------------------

Comment (by marisn):

Replying to [comment:1 mlennert]:
> Replying to [ticket:2912 andbal]:
> > Writing a python script, I found that the
{{{grass.script.raster_what()}}} output dictionary has different keys
depending on language used in GRASS.
>
>
> This comes from line 191 in lib/python/script/raster.py where these
labels are noted as translatable strings. I agree that this is a very bad
idea and that such dictionary keys should not be translatable.
>
> Unless anyone gives a good reason for the contrary, I will change the
vector of labels to non-translatable. This might break existing scripts,
but I think this is necessary.
Then also add line 184 ("No data").

This also needs to be explicitly stated in docstring that it is callers
responsibility to use localized version of key values before they are
displayed to the end user.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2912#comment:2&gt;
GRASS GIS <https://grass.osgeo.org>

#2912: raster_what() not compliant with localised version of GRASS
---------------------+---------------------------------------------
  Reporter: andbal | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.4
Component: Python | Version: svn-trunk
Resolution: | Keywords: grass.script python translation
       CPU: x86-64 | Platform: Linux
---------------------+---------------------------------------------

Comment (by lucadelu):

Replying to [comment:1 mlennert]:
> Replying to [ticket:2912 andbal]:
> > Writing a python script, I found that the
{{{grass.script.raster_what()}}} output dictionary has different keys
depending on language used in GRASS.
>
>
> This comes from line 191 in lib/python/script/raster.py where these
labels are noted as translatable strings. I agree that this is a very bad
idea and that such dictionary keys should not be translatable.
>
> Unless anyone gives a good reason for the contrary, I will change the
vector of labels to non-translatable. This might break existing scripts,
but I think this is necessary.

In the attached diff I propose a change, because the actual behavior is
useful for GUI modules but not for other uses

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2912#comment:3&gt;
GRASS GIS <https://grass.osgeo.org>

#2912: raster_what() not compliant with localised version of GRASS
---------------------+---------------------------------------------
  Reporter: andbal | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.4
Component: Python | Version: svn-trunk
Resolution: | Keywords: grass.script python translation
       CPU: x86-64 | Platform: Linux
---------------------+---------------------------------------------
Changes (by lucadelu):

* Attachment "raster_what.diff" added.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2912&gt;
GRASS GIS <https://grass.osgeo.org>

#2912: raster_what() not compliant with localised version of GRASS
---------------------+---------------------------------------------
  Reporter: andbal | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.4
Component: Python | Version: svn-trunk
Resolution: | Keywords: grass.script python translation
       CPU: x86-64 | Platform: Linux
---------------------+---------------------------------------------
Changes (by lucadelu):

* Attachment "raster_what.diff" removed.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2912&gt;
GRASS GIS <https://grass.osgeo.org>

#2912: raster_what() not compliant with localised version of GRASS
---------------------+---------------------------------------------
  Reporter: andbal | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.4
Component: Python | Version: svn-trunk
Resolution: | Keywords: grass.script python translation
       CPU: x86-64 | Platform: Linux
---------------------+---------------------------------------------

Comment (by annakrat):

Replying to [comment:3 lucadelu]:
> In the attached diff I propose a change, because the actual behavior is
useful for GUI modules but not for other uses

I would prefer to avoid the `gui` parameter. Instead we could have a
wrapper function raster_what in wxpython/core/utils.py which would replace
the labels with the translatable ones? Sorry, no time for this right now,
maybe later.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2912#comment:4&gt;
GRASS GIS <https://grass.osgeo.org>

#2912: raster_what() not compliant with localised version of GRASS
---------------------+---------------------------------------------
  Reporter: andbal | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.4
Component: Python | Version: svn-trunk
Resolution: | Keywords: grass.script python translation
       CPU: x86-64 | Platform: Linux
---------------------+---------------------------------------------

Comment (by lucadelu):

Replying to [comment:4 annakrat]:
>
> I would prefer to avoid the `gui` parameter. Instead we could have a
wrapper function raster_what in wxpython/core/utils.py which would replace
the labels with the translatable ones? Sorry, no time for this right now,
maybe later.

Can you explain a little bit more why you don't like gui parameter? Your
proposal seems to me a duplication of code...

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2912#comment:5&gt;
GRASS GIS <https://grass.osgeo.org>

#2912: raster_what() not compliant with localised version of GRASS
---------------------+---------------------------------------------
  Reporter: andbal | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.4
Component: Python | Version: svn-trunk
Resolution: | Keywords: grass.script python translation
       CPU: x86-64 | Platform: Linux
---------------------+---------------------------------------------

Comment (by annakrat):

Replying to [comment:5 lucadelu]:
> Replying to [comment:4 annakrat]:
> >
> > I would prefer to avoid the `gui` parameter. Instead we could have a
wrapper function raster_what in wxpython/core/utils.py which would replace
the labels with the translatable ones? Sorry, no time for this right now,
maybe later.
>
> Can you explain a little bit more why you don't like gui parameter? Your
proposal seems to me a duplication of code...

I didn't like the gui parameter, perhaps `localized=False` would make more
sense when you want to use localized names in a script, not just in the
gui.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2912#comment:6&gt;
GRASS GIS <https://grass.osgeo.org>

#2912: raster_what() not compliant with localised version of GRASS
---------------------+---------------------------------------------
  Reporter: andbal | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.4
Component: Python | Version: svn-trunk
Resolution: | Keywords: grass.script python translation
       CPU: x86-64 | Platform: Linux
---------------------+---------------------------------------------

Comment (by lucadelu):

Replying to [comment:6 annakrat]:

>
> I didn't like the gui parameter, perhaps `localized=False` would make
more sense when you want to use localized names in a script, not just in
the gui.

Ok, if it is only parameter's name, it is not problem to change. I like
`localized`. Could I submit the code with `localized` parameter instead
`gui` one?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2912#comment:7&gt;
GRASS GIS <https://grass.osgeo.org>

#2912: raster_what() not compliant with localised version of GRASS
---------------------+---------------------------------------------
  Reporter: andbal | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.4
Component: Python | Version: svn-trunk
Resolution: | Keywords: grass.script python translation
       CPU: x86-64 | Platform: Linux
---------------------+---------------------------------------------

Comment (by annakrat):

Replying to [comment:7 lucadelu]:
> Replying to [comment:6 annakrat]:
>
> >
> > I didn't like the gui parameter, perhaps `localized=False` would make
more sense when you want to use localized names in a script, not just in
the gui.
>
> Ok, if it is only parameter's name, it is not problem to change. I like
`localized`. Could I submit the code with `localized` parameter instead
`gui` one?

Sure, if you tested it with different locale and it behaves as expected.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2912#comment:8&gt;
GRASS GIS <https://grass.osgeo.org>

#2912: raster_what() not compliant with localised version of GRASS
---------------------+---------------------------------------------
  Reporter: andbal | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.4
Component: Python | Version: svn-trunk
Resolution: | Keywords: grass.script python translation
       CPU: x86-64 | Platform: Linux
---------------------+---------------------------------------------

Comment (by lucadelu):

Replying to [comment:8 annakrat]:

>
> Sure, if you tested it with different locale and it behaves as expected.

committed with test in r67874.
Tests are needed before backport.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2912#comment:9&gt;
GRASS GIS <https://grass.osgeo.org>

#2912: raster_what() not compliant with localised version of GRASS
---------------------+---------------------------------------------
  Reporter: andbal | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.4
Component: Python | Version: svn-trunk
Resolution: | Keywords: grass.script python translation
       CPU: x86-64 | Platform: Linux
---------------------+---------------------------------------------

Comment (by andbal):

Replying to [comment:9 lucadelu]:
> Tests are needed before backport.
I tried the testsuite code with two languages other than english and gave
back 'OK' in both cases.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2912#comment:10&gt;
GRASS GIS <https://grass.osgeo.org>

#2912: raster_what() not compliant with localised version of GRASS
---------------------+---------------------------------------------
  Reporter: andbal | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: major | Milestone: 7.0.4
Component: Python | Version: svn-trunk
Resolution: fixed | Keywords: grass.script python translation
       CPU: x86-64 | Platform: Linux
---------------------+---------------------------------------------
Changes (by andbal):

* status: new => closed
* resolution: => fixed

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2912#comment:11&gt;
GRASS GIS <https://grass.osgeo.org>

#2912: raster_what() not compliant with localised version of GRASS
---------------------+---------------------------------------------
  Reporter: andbal | Owner: grass-dev@…
      Type: defect | Status: reopened
  Priority: major | Milestone: 7.0.4
Component: Python | Version: svn-trunk
Resolution: | Keywords: grass.script python translation
       CPU: x86-64 | Platform: Linux
---------------------+---------------------------------------------
Changes (by annakrat):

* status: closed => reopened
* resolution: fixed =>

Comment:

As far as I know, it hasn't been backported yet.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2912#comment:12&gt;
GRASS GIS <https://grass.osgeo.org>

#2912: raster_what() not compliant with localised version of GRASS
---------------------+---------------------------------------------
  Reporter: andbal | Owner: grass-dev@…
      Type: defect | Status: reopened
  Priority: major | Milestone: 7.0.5
Component: Python | Version: svn-trunk
Resolution: | Keywords: grass.script python translation
       CPU: x86-64 | Platform: Linux
---------------------+---------------------------------------------

Comment (by martinl):

Can be backport done?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2912#comment:14&gt;
GRASS GIS <https://grass.osgeo.org>

#2912: raster_what() not compliant with localised version of GRASS
---------------------+---------------------------------------------
  Reporter: andbal | Owner: grass-dev@…
      Type: defect | Status: reopened
  Priority: major | Milestone: 7.0.5
Component: Python | Version: svn-trunk
Resolution: | Keywords: grass.script python translation
       CPU: x86-64 | Platform: Linux
---------------------+---------------------------------------------

Comment (by annakrat):

Replying to [comment:14 martinl]:
> Can be backport done?
Yes, please do it.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2912#comment:15&gt;
GRASS GIS <https://grass.osgeo.org>

#2912: raster_what() not compliant with localised version of GRASS
---------------------+---------------------------------------------
  Reporter: andbal | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: major | Milestone: 7.0.5
Component: Python | Version: svn-trunk
Resolution: fixed | Keywords: grass.script python translation
       CPU: x86-64 | Platform: Linux
---------------------+---------------------------------------------
Changes (by lucadelu):

* status: reopened => closed
* resolution: => fixed

Comment:

In [changeset:"69242" 69242]:
{{{
#!CommitTicketReference repository="" revision="69242"
python script: backported raster_what function to work with or without
localized labels fixed #2912
}}}

--
Ticket URL: </ticket/2912#comment:16>
GRASS GIS <https://grass.osgeo.org>