Skip to content

libgis: Do not use translated unit and projection names as data - #742

Open
echoix wants to merge 5 commits into
mainfrom
claude/grass-locale-tests-fhqkb8
Open

echoix wants to merge 5 commits into
mainfrom
claude/grass-locale-tests-fhqkb8

Conversation

@echoix

@echoix echoix commented Oct 11, 2026 •

Copy link
Copy Markdown
Owner

Running the test suite in a translated locale (de_DE, fr_FR, tr_TR) showed that translated text is used as data in several places, and that many tests assert English messages.

Code (libgis and tools)

  • G_database_units_to_meters_factor() compared the translated unit name with English names and returned 0 for projects without a conversion factor (e.g. XY). In de_DE and fr_FR this gave slope 0 instead of 45 in r.slope.aspect, length 0 in v.geometry, and failures in r.sim.water/r.sim.sediment.
  • G_units(NULL) and G_get_units_name() parsed the translated name of the database units. This gave an unknown unit in French.
  • m.measure (JSON, shell), r3.info (-g, JSON), r3.out.netcdf (value written into the file) and g.region (JSON crs.name) used translated names.
  • New G_get_units_name_untranslated(), G_projection_name_untranslated() and G_database_projection_name_untranslated(); the translated functions are unchanged. Rast3d_get_vertical_unit() now returns the English name.

Tests

  • LANGUAGE=C is set for gunittest (invoker and test()) and for pytest (a session fixture in the conftest.py of each directory with tests; a root conftest.py would be deleted by an autotools configure), because the tests check English messages.

Verification

Full gunittest and pytest runs (nc_spm_full_v2beta1, NLS enabled) under C.UTF-8, de_DE.UTF-8, fr_FR.UTF-8 and tr_TR.UTF-8 give the same results with these changes: the same 9 failing gunittest files and the same 6 failing pytest tests plus 1 error as the baseline, all unrelated to the locale. Before the changes, 8 (de, fr) and 3 (tr) more gunittest files, and 108 (de), 115 (fr) and 15 (tr) more pytest tests, failed. The full runs were done before the pytest setting moved from a root conftest.py to the per-directory ones; the affected pytest files were run again in all four locales after the move.

Not covered: lib/ogsf/gsd_objs.c:1230,1236 compares a translated unit name with "meters". It was found by reading and not built or tested here, so it is not changed.

Larger use of AI: the investigation, the fixes and this text were prepared with an AI assistant (Claude Code). The localize flag in lib/gis/units.c is a mechanical change, with each _("...") literal kept so xgettext still finds it.

G_get_units_name() and G_projection_name() return translated text. Using
it as data breaks in a translated locale:

- G_database_units_to_meters_factor() compared the translated unit name
  with English names and returned 0 for projects without a conversion
  factor (e.g. XY), which breaks r.slope.aspect, r.sim.water and
  v.to.db.
- G_units(NULL) and G_get_units_name() parsed the translated name of the
  database units to get the units code, which gave an unknown unit when
  the translation was not the English name (e.g. in French).
- m.measure, r3.info, r3.out.netcdf and g.region wrote translated names
  into JSON, shell style output and files.

Add G_get_units_name_untranslated(), G_projection_name_untranslated() and
G_database_projection_name_untranslated() and use them for such data.
Get the database units by code with G_database_unit().
Rast3d_get_vertical_unit() now returns the English name.
The tests check English messages, so many of them fail when run in a
translated locale. Set LANGUAGE=C for the tests run with the gunittest
invoker and with pytest, where the test files are not run with the
invoker.
Comment thread lib/gis/units.c Outdated
Comment thread lib/gis/units.c Outdated
Comment thread conftest.py Outdated
An autotools configure run deletes conftest* files in the source tree, so
a root conftest.py cannot hold the setting. Use a session fixture in the
conftest.py of each directory with pytest tests instead.
Ruff rule RUF076 does not allow autouse fixtures. Set LANGUAGE when the
conftest.py files are imported instead, which happens during collection,
before any test runs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants