You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried dynamically setting LC_CTYPE to something sensible before printing error messages, but it doesn't work. As ?Sys.setlocale states:
Attempts to change the character set (by ‘Sys.setlocale("LC_TYPE",
)’, if that implies a different character set) during a session
may not work and are likely to lead to some confusion.
So you have to set the locale before you do anything useful. My current thought is that (at least under Wnidows) if the LANG environment variable is set, then you should check the LC_CTYPE locale setting any time you load a package with translations and wrn the user that they need to set this to something sensible.
For Linux it's enough to check that LC_MESSAGES is in a UTF-8 locale. I think all OS X locales are UTF-8 anyway, but I have no idea about BSD or Solaris.
check_localization<-function(code)
{
if(.Platform$OS.type=="windows")
{
lang<- Sys.getenv("LANG", NA)
if(!is.na(lang))
{
lc_ctype<- Sys.getlocale("LC_CTYPE")
# TODO: all the rest of ISO 639-1new_lc_ctype<-switch(
lang,
de="German",
en="English",
fr="French",
hu="Hungarian",
ko="Korean",
nl="Dutch",
ru="Russian",
sv="Swedish",
tr="Turkish",
uk="Ukranian"
)
if(!grepl(new_lc_ctype, lc_ctype))
{
warning(
"You have set the LANG environment variable to ",
lang,
" but the LC_CTYPE locale setting is ",
lc_ctype,
" which may result in error messages being incorrectly displayed.\n",
'Consider setting Sys.setlocale("LC_CTYPE", "',
new_lc_ctype,
'").'
)
}
}
} elseif(Sys.info()["sysname"] =="Linux")
{
lc_messages<- Sys.getlocale("LC_MESSAGES")
# Possibly better to check l10n_info()$`UTF-8`?if(!grepl("utf8", lc_messages))
{
new_lc_messages<- paste0(lc_messages, ".utf8")
warning(
"The LC_MESSAGES locale setting is not UTF-8, which may result in error messages being incorrectly displayed.\n",
'Consider setting Sys.setlocale("LC_MESSAGES", "',
new_lc_messages,
'").'
)
}
}
}
In
setlang
, the current code sets theLANG
environment variable. On Linux, this may also (or alternatively) need to set a locale, e.g.:There's also this issue about platform-dependent printing of UTF-8 messages.
h/t @richierocks
The text was updated successfully, but these errors were encountered: