[GRASS-dev] Re: [GRASS-SVN] r33171 - in grass/trunk: lib/gis raster/r.colors

Hi,

I wonder about localization of colors descriptions...

Martin

2008/8/30 <svn_grass@osgeo.org>:

Author: glynn
Date: 2008-08-30 13:21:59 -0400 (Sat, 30 Aug 2008)
New Revision: 33171

Added:
  grass/trunk/lib/gis/colors.desc
Modified:
  grass/trunk/lib/gis/Makefile
  grass/trunk/raster/r.colors/main.c
Log:
Read descriptions for etc/colors/* from etc/colors.desc

Modified: grass/trunk/lib/gis/Makefile

--- grass/trunk/lib/gis/Makefile 2008-08-30 17:08:52 UTC (rev 33170)
+++ grass/trunk/lib/gis/Makefile 2008-08-30 17:21:59 UTC (rev 33171)
@@ -23,7 +23,7 @@
EXTRA_LIBS += $(GDALLIBS)
endif

-default: lib $(FMODE_OBJ) $(DATAFILES) $(COLORFILES)
+default: lib $(FMODE_OBJ) $(DATAFILES) $(COLORFILES) $(ETC)/colors.desc

$(FMODE_OBJ): fmode.dat
       @test -d $(OBJDIR) || mkdir $(OBJDIR)

Added: grass/trunk/lib/gis/colors.desc

--- grass/trunk/lib/gis/colors.desc (rev 0)
+++ grass/trunk/lib/gis/colors.desc 2008-08-30 17:21:59 UTC (rev 33171)
@@ -0,0 +1,29 @@
+aspect: aspect oriented grey colors
+aspectcolr: aspect oriented rainbow colors
+bcyr: blue through cyan through yellow to red
+bgyr: blue through green through yellow to red
+byg: blue through yellow to green
+byr: blue through yellow to red
+curvature: for terrain curvatures (from v.surf.rst and r.slope.aspect curvature colors)
+differences: differences oriented colors
+elevation: maps percentage ranges of raster values to elevation color ramp
+etopo2: rainbow color ramp for the ETOPO2 2-minute Worldwide Bathymetry/Topography dataset
+evi: enhanced vegetative index colors
+grey: grey scale
+grey1.0: grey scale for raster values between 0.0-1.0
+grey255: grey scale for raster values bewtween 0-255
+grey.eq: histogram-equalized grey scale
+grey.log: histogram logarithmic transformed grey scale
+gyr: green through yellow to red
+ndvi: Normalized Difference Vegetation Index colors
+population: color table covering human population classification breaks
+rainbow: rainbow color table
+ramp: color ramp
+random: random color table
+ryb: red through yellow to blue
+ryg: red through yellow to green
+sepia: yellowish-brown through to white
+slope: r.slope.aspect-type slope colors for raster values 0-90
+srtm: color palette for Shuttle Radar Topography Mission elevation values
+terrain: global elevation color table covering -11000 to +8850m
+wave: color wave

Modified: grass/trunk/raster/r.colors/main.c

--- grass/trunk/raster/r.colors/main.c 2008-08-30 17:08:52 UTC (rev 33170)
+++ grass/trunk/raster/r.colors/main.c 2008-08-30 17:21:59 UTC (rev 33171)
@@ -73,6 +73,46 @@
    return list;
}

+static char *rules_descriptions(void)
+{
+ char path[GPATH_MAX];
+ struct Key_Value *kv;
+ int result_len = 0;
+ int result_max = 2000;
+ char *result = G_malloc(result_max);
+ int stat;
+ int i;
+
+ sprintf(path, "%s/etc/colors.desc", G_gisbase());
+ kv = G_read_key_value_file(path, &stat);
+ if (!kv || stat < 0)
+ return NULL;
+
+ for (i = 0; i < nrules; i++) {
+ const char *name = rules[i];
+ const char *desc = G_find_key_value(name, kv);
+ int len;
+
+ if (!desc)
+ desc = "no description";
+
+ desc = _(desc);
+
+ len = strlen(name) + strlen(desc) + 2;
+ if (result_len + len >= result_max) {
+ result_max = result_len + len + 1000;
+ result = G_realloc(result, result_max);
+ }
+
+ sprintf(result + result_len, "%s;%s;", name, desc);
+ result_len += len;
+ }
+
+ G_free_key_value(kv);
+
+ return result;
+}
+
static void list_rules(void)
{
    int i;
@@ -152,36 +192,7 @@
    opt.colr->required = NO;
    opt.colr->options = rules_list();
    opt.colr->description = _("Type of color table");
- opt.colr->descriptions =
- _("aspect;aspect oriented grey colors;"
- "aspectcolr;aspect oriented rainbow colors;"
- "bcyr;blue through cyan through yellow to red;"
- "bgyr;blue through green through yellow to red;"
- "byg;blue through yellow to green;"
- "byr;blue through yellow to red;"
- "curvature;for terrain curvatures (from v.surf.rst and r.slope.aspect curvature colors);"
- "differences;differences oriented colors;"
- "elevation;maps percentage ranges of raster values to elevation color ramp;"
- "etopo2;rainbow color ramp for the ETOPO2 2-minute Worldwide Bathymetry/Topography dataset;"
- "evi;enhanced vegetative index colors;"
- "grey;grey scale;"
- "grey1.0;grey scale for raster values between 0.0-1.0;"
- "grey255;grey scale for raster values bewtween 0-255;"
- "grey.eq;histogram-equalized grey scale;"
- "grey.log;histogram logarithmic transformed grey scale;"
- "gyr;green through yellow to red;"
- "ndvi;Normalized Difference Vegetation Index colors;"
- "population;color table covering human population classification breaks;"
- "rainbow;rainbow color table;"
- "ramp;color ramp;"
- "random;random color table;"
- "ryb;red through yellow to blue;"
- "ryg;red through yellow to green;"
- "sepia;yellowish-brown through to white;"
- "slope;r.slope.aspect-type slope colors for raster values 0-90;"
- "srtm;color palette for Shuttle Radar Topography Mission elevation values;"
- "terrain;global elevation color table covering -11000 to +8850m;"
- "wave;color wave;");
+ opt.colr->descriptions = rules_descriptions();
    opt.colr->guisection = _("Colors");

    flag.r = G_define_flag();

_______________________________________________
grass-commit mailing list
grass-commit@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-commit

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa *

Martin Landa wrote:

I wonder about localization of colors descriptions...

Author: glynn
Date: 2008-08-30 13:21:59 -0400 (Sat, 30 Aug 2008)
New Revision: 33171

Added:
  grass/trunk/lib/gis/colors.desc
Modified:
  grass/trunk/lib/gis/Makefile
  grass/trunk/raster/r.colors/main.c
Log:
Read descriptions for etc/colors/* from etc/colors.desc

None of the existing .po files include a translation for
opt.colr->descriptions.

The new code passes each description to _() individually, which is
probably more useful (i.e. each description is translated separately,
so the translation doesn't become invalid each time a new description
is added).

OTOH, xgettext won't find the source strings by itself; they'll need
to be added manually. That's an inevitable consequence of not
embedding the descriptions in the source code (it seems a bit
pointless being able to just drop new colour tables into etc/colors
but then needing to re-compile r.colors to add the description).

--
Glynn Clements <glynn@gclements.plus.com>

On Sat, Aug 30, 2008 at 10:33 PM, Glynn Clements
<glynn@gclements.plus.com> wrote:

Martin Landa wrote:

Author: glynn
Date: 2008-08-30 13:21:59 -0400 (Sat, 30 Aug 2008)
New Revision: 33171

Added:
  grass/trunk/lib/gis/colors.desc
Modified:
  grass/trunk/lib/gis/Makefile
  grass/trunk/raster/r.colors/main.c
Log:
Read descriptions for etc/colors/* from etc/colors.desc

...

(it seems a bit
pointless being able to just drop new colour tables into etc/colors
but then needing to re-compile r.colors to add the description).

I have backported this, with the addition of
rules: create new color table based on user-specified rules
as needed in 6.4.svn.

Related wish: could the list be printed in alphabetical order?
While the colors.desc file is ordered, the help text is no more:

r.colors help
...
   color Type of color table
           options: aspect,aspectcolr,bcyr,bgyr,byg,byr,curvature,
                    differences,elevation,etopo2,evi,grey,grey1.0,grey255,
                    gyr,ndvi,population,rainbow,ramp,ryb,ryg,sepia,slope,
                    srtm,terrain,wave,random,grey.eq,grey.log
            aspect: aspect oriented grey colors
            aspectcolr: aspect oriented rainbow colors
            bcyr: blue through cyan through yellow to red
            bgyr: blue through green through yellow to red
            byg: blue through yellow to green
            byr: blue through yellow to red
            curvature: for terrain curvatures (from v.surf.rst and
r.slope.aspect curvature colors)
            differences: differences oriented colors
            elevation: maps percentage ranges of raster values to
elevation color ramp
            etopo2: rainbow color ramp for the ETOPO2 2-minute
Worldwide Bathymetry/Topography dataset
            evi: enhanced vegetative index colors
            grey: grey scale
            grey1.0: grey scale for raster values between 0.0-1.0
            grey255: grey scale for raster values bewtween 0-255
            gyr: green through yellow to red
            ndvi: Normalized Difference Vegetation Index colors
            population: color table covering human population
classification breaks
            rainbow: rainbow color table
            ramp: color ramp
            ryb: red through yellow to blue
            ryg: red through yellow to green
            sepia: yellowish-brown through to white
            slope: r.slope.aspect-type slope colors for raster values 0-90
            srtm: color palette for Shuttle Radar Topography Mission
elevation values
            terrain: global elevation color table covering -11000 to +8850m
            wave: color wave
            random: random color table
            grey.eq: histogram-equalized grey scale
            grey.log: histogram logarithmic transformed grey scale

I am not sure where the order magic is.

Markus

Markus Neteler wrote:

Related wish: could the list be printed in alphabetical order?
While the colors.desc file is ordered, the help text is no more:

The rules are almost ordered; the only exception is that the "special"
rules (those which are coded rather than read from etc/colors/*, i.e.
random, grey.eq, grey.log and rules) are listed last.

If you want to re-sort the list after those are added:

  static int cmp_names(const void *aa, const void *bb)
  {
      char *const *a = (char *const *)aa;
      char *const *b = (char *const *)bb;
  
      return strcmp(*a, *b);
  }

  static void scan_rules(void)
  {
  ...
      qsort(rules, nrules, sizeof(char *), cmp_names);
  }

Personally, I would be inclined to leave the special rules at the end.

--
Glynn Clements <glynn@gclements.plus.com>