Bug 17303 - geterrmessage(), but ignoring LANG environment variable
Summary: geterrmessage(), but ignoring LANG environment variable
Alias: None
Product: R
Classification: Unclassified
Component: Wishlist (show other bugs)
Version: R-devel (trunk)
Hardware: All All
: P5 enhancement
Assignee: R-core
Depends on:
Reported: 2017-07-05 12:38 UTC by Richard Cotton
Modified: 2017-08-11 14:13 UTC (History)
2 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Richard Cotton 2017-07-05 12:38:18 UTC
As part of the RL10N project (https://github.com/RL10N), I've been asking lots of speakers of languages other than English about how useful it would be to have   error messages translated into other languages.

One piece of opposition I've heard is that if you don't understand an error message, you need to type the message into an internet search engine, and you get better results if this message is in English.

That is, an optimal workflow is

1. See the error message in your language of choice, then
2. If it does not make sense, see it again in English.

To make part 2 possible, I want something like geterrmessage() that ignores the LANG environment variable. 

For example,

# Set the messaging language to French
Sys.setenv(LANG = "fr")

# Throw an error
1 + @

# Retrieve the last error message
## [1] "Erreur : '@' inattendu(e) in \"1 + @\"\n"

I want to be able to get the error message in English using something like

## [1] "Error: unexpected '@' in \"1 + @\"\n"

I don't know how to get this functionality from an external package; I suspect it needs to be built into R at a low level.
Comment 1 Duncan Murdoch 2017-07-09 12:41:40 UTC
This looks quite hard to do.  R uses the gettext function from libintl to translate messages.  These are often used as format strings rather than literal strings.  The result after sprintf() (or a related function, I haven't looked) acts on the format string and other input data is used in the signalled error, and also saved in a buffer.  geterrmessage() just reports what is in the buffer.

To do what you want, I think the following approach might work:

 The translation macro _() (and related functions) would save the input string somewhere and return the translated string.

 The error() function (and related functions) would produce the error message twice, once from the saved input string, once from the translated string.  It
would generate the error using the translation, but save both of them.

The geterrmessage() function wouldn't need to change, but getenglisherrmessage()
would get its result from the other saved result.

This approach would fail in those rare(?) cases where several strings are translated, and something other than the last one is passed to the error() function.  If these really are rare, they could conceivably all be modified to work.

This looks tricky, and might not succeed.  It's certainly a lot of work.  I'm not going to attempt it, but perhaps someone in RL10N would want to take it on.
Comment 2 Martin Maechler 2017-08-11 14:13:39 UTC
Duncan M  said everything: It would need quite a bit of work, and may be hard to achieve w/o breaking the current API.

We agree it is a reasonable wish, and so will be happy to collaborate with whoever is both capable and willing to do the work.
Till then, this is 'Wishlist'