Skip to content

Commit

Permalink
Sys.setLanguage(): default C.vs.en = "silent"
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@87056 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
maechler committed Aug 26, 2024
1 parent e700475 commit 76040e2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
17 changes: 11 additions & 6 deletions src/library/base/R/stop.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,23 @@ gettextf <- function(fmt, ..., domain = NULL, trim = TRUE)

## Could think of using *several* domains, i.e. domain = vector; but seems complicated;
## the default domain="R" seems to work for all of base R: {"R", "R-base", "RGui"}
Sys.setLanguage <- function(lang, unset = "en", allowC4en = TRUE)
Sys.setLanguage <- function(lang, unset = "en", C.vs.en = c("silent", "msg", "warn"))
{
if (!capabilities("NLS") || is.na(.popath)) {
warning(gettextf("no natural language support or missing translations"), domain=NA)
return(invisible(structure("", ok = FALSE)))
}
stopifnot(is.character(lang), length(lang) == 1L, # e.g., "es" , "fr_CA"
lang == "C" || grepl("^[a-z][a-z]", lang))
curLang <- Sys.getenv("LANGUAGE", unset = NA) # so it can be reset
if (!capabilities("NLS") || is.na(.popath)) {
warning(gettextf("no natural language support or missing translations"), domain=NA)
return(invisible(structure(curLang, ok = FALSE)))
}
if(is.na(curLang) || !nzchar(curLang))
curLang <- unset # "factory" default
Warning <- if(allowC4en && startsWith(lang, "en")) message else warning
Warning <- if(startsWith(lang, "en"))
switch(match.arg(C.vs.en),
silent = function(...){},
msg = message,
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")
Expand Down
12 changes: 7 additions & 5 deletions src/library/base/man/gettext.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% File src/library/base/man/gettext.Rd
se% File src/library/base/man/gettext.Rd
% Part of the R package, https://www.R-project.org
% Copyright 1995-2024 R Core Team
% Distributed under GPL 2 or later
Expand Down Expand Up @@ -27,7 +27,7 @@ ngettext(n, msg1, msg2, domain = NULL)

bindtextdomain(domain, dirname = NULL)

Sys.setLanguage(lang, unset = "en", allowC4en = TRUE)
Sys.setLanguage(lang, unset = "en", C.vs.en = c("silent", "msg", "warn"))
}
\arguments{
\item{\dots}{one or more character vectors.}
Expand All @@ -46,9 +46,11 @@ Sys.setLanguage(lang, unset = "en", allowC4en = TRUE)
\item{unset}{a string, specifying the default language assumed to be
current in the case \code{\link{Sys.getenv}("LANGUAGE")} is unset or
empty.}
\item{allowC4en}{logical indicating if a current (sometimes \dQuote{hard})
setting of language \code{"C"} is acceptable for \code{lang = "en"}. In that
case, \code{\link{message}()} is called instead of \code{\link{warning}()}.}
\item{C.vs.en}{a string specifying how a current (sometimes \dQuote{hard})
setting of language \code{"C"} is treated for \code{lang = "en"}.
When \code{"silent"}, nothing is signalled, when \code{"msg"}, a
\code{\link{message}()} and if \code{"warn"} a \code{\link{warning}()}
is signalled.}
}
\details{
If \code{domain} is \code{NULL} (the default) in \code{gettext}
Expand Down

0 comments on commit 76040e2

Please sign in to comment.