Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions general/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Settings for pytest tests"""

import os

# The tests are written for English messages, so they would fail in a
# translated locale, e.g., when running on a system which is not English.
os.environ["LANGUAGE"] = "C"
4 changes: 3 additions & 1 deletion general/g.region/printwindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ void print_window(struct Cell_head *window, int print_flag, int flat_flag,

/* flag.print & flag.gprint */
if (print_flag & PRINT_REG) {
prj = G_database_projection_name();
/* machine-readable output must not depend on the locale */
prj = format == PLAIN ? G_database_projection_name()
: G_database_projection_name_untranslated();
if (!prj && format != JSON)
prj = "** unknown **";

Expand Down
7 changes: 7 additions & 0 deletions imagery/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Settings for pytest tests"""

import os

# The tests are written for English messages, so they would fail in a
# translated locale, e.g., when running on a system which is not English.
os.environ["LANGUAGE"] = "C"
3 changes: 3 additions & 0 deletions include/grass/defs/gis.h
Original file line number Diff line number Diff line change
Expand Up @@ -714,11 +714,13 @@ int G_projection(void);
/* proj2.c */
int G_projection_units(int);
const char *G_projection_name(int);
const char *G_projection_name_untranslated(int);

/* proj3.c */
const char *G_database_unit_name(int);
int G_database_unit(void);
const char *G_database_projection_name(void);
const char *G_database_projection_name_untranslated(void);
const char *G_database_datum_name(void);
const char *G_database_ellipse_name(void);
double G_database_units_to_meters_factor(void);
Expand Down Expand Up @@ -846,6 +848,7 @@ void G_trim_decimal(char *);
double G_meters_to_units_factor(int);
double G_meters_to_units_factor_sq(int);
const char *G_get_units_name(int, int, int);
const char *G_get_units_name_untranslated(int, int, int);
int G_units(const char *);
int G_is_units_type_spatial(int);
int G_is_units_type_temporal(int);
Expand Down
7 changes: 7 additions & 0 deletions lib/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Settings for pytest tests"""

import os

# The tests are written for English messages, so they would fail in a
# translated locale, e.g., when running on a system which is not English.
os.environ["LANGUAGE"] = "C"
30 changes: 30 additions & 0 deletions lib/gis/proj2.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ int G_projection_units(int n)
/*!
\brief Get projection name

The name is translated, so it is meant for messages and other text for
people. Use G_projection_name_untranslated() for machine-readable output.

\param n projection code

\return projection name
Expand All @@ -65,3 +68,30 @@ const char *G_projection_name(int n)
return NULL;
}
}

/*!
\brief Get projection name in English, independent of the locale

Same as G_projection_name(), but never translated, so the result is
suitable for machine-readable output (JSON, shell style).

\param n projection code

\return projection name
\return NULL on error
*/
const char *G_projection_name_untranslated(int n)
{
switch (n) {
case PROJECTION_XY:
return "x,y";
case PROJECTION_UTM:
return "UTM";
case PROJECTION_LL:
return "Latitude-Longitude";
case PROJECTION_OTHER:
return "Other Projection";
default:
return NULL;
}
}
30 changes: 29 additions & 1 deletion lib/gis/proj3.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,33 @@ const char *G_database_projection_name(void)
return name;
}

/*!
\brief Get projection name for the current location in English

Same as G_database_projection_name(), but never translated, so the result
is suitable for machine-readable output (JSON, shell style).

\return projection name
*/
const char *G_database_projection_name_untranslated(void)
{
int n;
const char *name;

switch (n = G_projection()) {
case PROJECTION_XY:
case PROJECTION_UTM:
case PROJECTION_LL:
return G_projection_name_untranslated(n);
}

name = lookup_proj("name");
if (!name)
return "Unknown projection";

return name;
}

/*!
\brief Conversion to meters

Expand Down Expand Up @@ -161,7 +188,8 @@ double G_database_units_to_meters_factor(void)
if (buf)
sscanf(buf, "%lf", &factor);
if (factor <= 0.0) {
unit = G_database_unit_name(0);
/* the table has English names, so the translated name does not match */
unit = G_get_units_name_untranslated(G_database_unit(), 0, FALSE);
for (n = 0; table[n].unit; n++)
if (equal(unit, table[n].unit)) {
factor = table[n].factor;
Expand Down
Loading
Loading