Skip to content

Commit

Permalink
Sys.setLanguage(): tweak "C" case
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@87081 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
maechler committed Aug 30, 2024
1 parent 719b3c8 commit d3bfbfe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/library/base/R/stop.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,16 @@ Sys.setLanguage <- function(lang, unset = "en", C.vs.en = c("msg", "warn", "sile
warn = warning)
else warning
if(identical("C", Sys.getlocale()) && lang != "C") { ## e.g. LC_ALL=C R on Linux
lcSet <- if(.Platform[["OS.type"]] == "unix")
Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
## TODOs: 1) does en_US.UTF-8 always exist?
lcSet <- if(.Platform[["OS.type"]] == "unix") # works to "undo LC_ALL=C"
paste0(collapse="", vapply(c("LC_ALL", "LC_MESSAGES"),
\(a) Sys.setlocale(a, "en_US.UTF-8"), ""))
## TODOs: 1) we assume en_US.UTF-8 exists on all "unix"
## 2) How to deal w/ Windows ? {can set things but with *no* effect}
ok.lc <- !is.null(lcSet) && nzchar(lcSet) # NULL or "" are not ok
if(!ok.lc)
Warning(gettextf("In a bare C locale, could not change language"), domain=NA)
Warning(gettextf(
"In bare C locale: LANGUAGE reset, but message language may be unchanged"),
domain=NA)
} else ok.lc <- TRUE
ok <- Sys.setenv(LANGUAGE=lang)
if(!ok)
Expand Down
8 changes: 4 additions & 4 deletions src/library/base/man/locales.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@ Sys.setenv("LANGUAGE" = "es") # set the language for error/warning messages
sep <- switch(Sys.info()[["sysname"]],
"Darwin"=, "SunOS" = "/",
"Linux" =, "Windows" = ";")
##' show a "full" Sys.getlocale() nicely:
showL <- function(loc) {
##' named vector from a "full" Sys.getlocale() :
asNvec <- function(loc) {
sl <- strsplit(strsplit(loc, sep)[[1L]], "=")
if(all(sapply(sl, length) == 2L))
if(all(lengths(sl) == 2L))
setNames(sapply(sl, `[[`, 2L), sapply(sl, `[[`, 1L))
else
setNames(as.character(sl), .LC.categories[1+seq_along(sl)])
}
print.Dlist(lloc <- showL(Sys.getlocale()))
print.Dlist(lloc <- asNvec(Sys.getlocale()))
## R-supported ones (but LC_ALL):
lloc[.LC.categories[-1]]
}
Expand Down

0 comments on commit d3bfbfe

Please sign in to comment.