Skip to content

R and LANGUAGE

2 messages · Martin Maechler

#
Diverted from  ESS-help.

It is really about R's LANGUAGE, locales  and
then a wish for   sessionInfo() :
>> Just guessing: perhaps this is something that is set when
    >> R is initialized and not queried every time something is
    >> printed?
    >> 
    >> Kasper

    > Hi Kasper:

    > Good guess, but wrong ;o) Actually, the problem is in
    > Sys.getlocale() Recent versions of R have this in its
    > help...

    >      Note that the ?LANGUAGE? environment variable has
    > precedence over ?"LC_MESSAGES"? in selecting the language
    > for message translation on most R platforms.

    > However, the function itself just ignores LANGUAGE.  I
    > searched bugzilla, but did not find anything related to
    > LANGUAGE or Sys.getlocale() I guess this is a feature :o)

Note that  'locale'  is general OS / system term, 
which R cannot define. 
On a Unix alike (e.g., here, Fedora Linux), if you have defined the 
   LC_*  plus LANG  plus LANGUAGE   
variables,

	locale

only  prints the  LC_* stuff  and LANG, but not LANGUAGE.
I did not dig, but I'm pretty sure  LANGUAGE is R's own way to specify
the messages language  *in addition* to locale settings,
and with higher precedence, as you've mentioned above.

Hence Sys.getlocale() should clearly  *not* report LANGUAGE.

OTOH,

  > Sys.getlocale()
  [1] "LC_CTYPE=de_CH.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=de_CH.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=de_CH.UTF-8;LC_PAPER=de_CH.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=de_CH.UTF-8;LC_IDENTIFICATION=C"
  > Sys.getenv("LANG")
  [1] "de_CH.UTF-8"
  > Sys.getenv("LANGUAGE")
  [1] "en"
  > 

So,  Sys.getlocale() also does not report  LANG,
even though,  'locale'  does report that for me.

--------------------------------------

After all the above, and a bit independent of that :

I believe you are right, and R's  sessionInfo()
should report something like LANGUAGE,
as that "hides" the setting of LC_MESSAGES.

Where "something like" could mean one of several possibilities:
a) in spite of the above, add  "LANGUAGE=.." to the locale part
   of sessionInfo()'s result.
b) A new entry LANGUAGE as part of the result.

And 'b)' typically should be combined with a tweak to the
print.sessionInfo()  method.  It could say
   "Language for messages:" instead of "LANGUAGE"

Martin

-
Martin Maechler, ETH Zurich
#
> Diverted from  ESS-help.
    > It is really about R's LANGUAGE, locales  and
    > then a wish for   sessionInfo() :
>>> Just guessing: perhaps this is something that is set when
    >>> R is initialized and not queried every time something is
    >>> printed?
    >>> 
    >>> Kasper

    >> Hi Kasper:

    >> Good guess, but wrong ;o) Actually, the problem is in
    >> Sys.getlocale() Recent versions of R have this in its
    >> help...

    >> Note that the ?LANGUAGE? environment variable has
    >> precedence over ?"LC_MESSAGES"? in selecting the language
    >> for message translation on most R platforms.

    >> However, the function itself just ignores LANGUAGE.  I
    >> searched bugzilla, but did not find anything related to
    >> LANGUAGE or Sys.getlocale() I guess this is a feature :o)

    > Note that  'locale'  is general OS / system term, 
    > which R cannot define. 
    > On a Unix alike (e.g., here, Fedora Linux), if you have defined the 
    > LC_*  plus LANG  plus LANGUAGE   
    > variables,

    > locale

    > only  prints the  LC_* stuff  and LANG, but not LANGUAGE.
    > I did not dig, but I'm pretty sure  LANGUAGE is R's own way to specify
    > the messages language  *in addition* to locale settings,
    > and with higher precedence, as you've mentioned above.

    > Hence Sys.getlocale() should clearly  *not* report LANGUAGE.

    > OTOH,

    >> Sys.getlocale()
    > [1] "LC_CTYPE=de_CH.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=de_CH.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=de_CH.UTF-8;LC_PAPER=de_CH.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=de_CH.UTF-8;LC_IDENTIFICATION=C"
    >> Sys.getenv("LANG")
    > [1] "de_CH.UTF-8"
    >> Sys.getenv("LANGUAGE")
    > [1] "en"
    >> 

    > So,  Sys.getlocale() also does not report  LANG,
    > even though,  'locale'  does report that for me.

I've been partly wrong and incomplete in what I said above.
Two kind fellow R corers pointed me to

the  'R-admin' manual

and to

    <http://www.gnu.org/software/gettext/manual/html_node/The-LANGUAGE-variable.html#The-LANGUAGE-variable>
    <http://www.gnu.org/software/gettext/manual/html_node/Locale-Environment-Variables.html#Locale-Environment-Variables>

for an explanation of LANGUAGE and other locale env vars.

and note that LANGUAGE is specific to GNU gettext, which is why we describe 
it as 'on many systems' .......
and also note that not installations / OSes are using the glibc
library for gettext which is also assumed in parts of the GNU
manuals above.

If (and how if)  sessionInfo() should be improved, by having it
report more about the LANG/LANGUAGE/LC_*   is a different topic,
that we will hopefully settle as well...

Martin.