Skip to content

Commit

Permalink
Never warn if LANGUAGE is set to "C" (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- authored Oct 28, 2024
1 parent 82daa90 commit f68d86b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
11 changes: 8 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# withr (development version)

* `local_language()` now never warns when set to `"C"` (#254).
This is a cross-platform and silent way of disabling `gettext()`
translations.


# withr 3.0.1

* Fixes for CRAN checks.
Expand Down Expand Up @@ -41,10 +46,10 @@

* `deferred_run()` can now be run at any point in a knitr file (#235).

* `local_tempfile()` now writes `lines` in UTF-8 (#210) and always uses
* `local_tempfile()` now writes `lines` in UTF-8 (#210) and always uses
`\n` for newlines (#216).

* `local_pdf()` and friends now correctly restore to the previously
* `local_pdf()` and friends now correctly restore to the previously
active device (#138).

* `local_()` now works even if withr isn't attached (#207).
Expand Down Expand Up @@ -132,7 +137,7 @@

* Lionel Henry is the new maintainer.

* Handlers registered with the global environment (as happens when `local_()`
* Handlers registered with the global environment (as happens when `local_()`
is run at the top-level, outside a function) are now automatically run
when the R session ends (#173).

Expand Down
33 changes: 18 additions & 15 deletions R/language.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,26 @@ local_language <- function(lang, .local_envir = parent.frame()) {
# https://stackoverflow.com/questions/6152321
lang <- gsub("-", "_", lang, fixed = TRUE)

if (!has_nls()) {
warning("Changing language has no effect when R installed without NLS")
}
# Only warn if setting `LANGUAGE` to something other than `"C"` (#254)
if (lang != "C") {
if (!has_nls()) {
warning("Changing language has no effect when R installed without NLS")
}

# > Note: The variable LANGUAGE is ignored if the locale is set to ‘C’.
# > In other words, you have to first enable localization, by setting LANG
# > (or LC_ALL) to a value other than ‘C’, before you can use a language
# > priority list through the LANGUAGE variable.
# --- https://www.gnu.org/software/gettext/manual/html_node/The-LANGUAGE-variable.html
# > Note: The variable LANGUAGE is ignored if the locale is set to ‘C’.
# > In other words, you have to first enable localization, by setting LANG
# > (or LC_ALL) to a value other than ‘C’, before you can use a language
# > priority list through the LANGUAGE variable.
# --- https://www.gnu.org/software/gettext/manual/html_node/The-LANGUAGE-variable.html

# `LC_ALL` has precedence over `LANG`. Check for the latter if the
# former is unset, otherwise check for the former.
if (Sys.getenv("LC_ALL", "") == "") {
# Causes too many failures because testthat sets `LANG` to "C"
# check_language_envvar("LANG")
} else {
check_language_envvar("LC_ALL")
# `LC_ALL` has precedence over `LANG`. Check for the latter if the
# former is unset, otherwise check for the former.
if (Sys.getenv("LC_ALL", "") == "") {
# Causes too many failures because testthat sets `LANG` to "C"
# check_language_envvar("LANG")
} else {
check_language_envvar("LC_ALL")
}
}

local_envvar(LANGUAGE = lang, .local_envir = .local_envir)
Expand Down

0 comments on commit f68d86b

Please sign in to comment.