diff --git a/R/language.R b/R/language.R index 737ee3b..d7541b9 100644 --- a/R/language.R +++ b/R/language.R @@ -44,14 +44,15 @@ local_language <- function(lang, .local_envir = parent.frame()) { } local_envvar(LANGUAGE = lang, .local_envir = .local_envir) - if (Sys.info()[["sysname"]] != "Windows") { - # Reset cache to avoid gettext() retrieving cached value from a previous - # language. I think this works because Sys.setlocale() calls setlocale() - # which https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=931456 claims - # resets the cache. So if there's some OS/setup that this technique fails - # on, we might try bindtextdomain() instead or as well. - local_locale(c(LC_MESSAGES = ""), .local_envir = .local_envir) - } + + # Reset cache to avoid gettext() retrieving cached value from a previous + # language (idea from https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=931456) + defer( + bindtextdomain("reset", local_tempdir()), + envir = .local_envir + ) + + invisible() } has_nls <- function() capabilities("NLS")[[1]] diff --git a/tests/testthat/test-language.R b/tests/testthat/test-language.R index 3c2935f..5b2c311 100644 --- a/tests/testthat/test-language.R +++ b/tests/testthat/test-language.R @@ -8,6 +8,9 @@ test_that("can temporarily change language", { # can use either _ or - expect_error(with_lang("pt_BR", "pt_BR", mean[[1]]), "não possível dividir") expect_error(with_lang("pt_BR", "pt-BR", mean[[1]]), "não possível dividir") + + # Is correctly reset (#213) + expect_error(mean[[1]], "not subsettable") }) test_that("warns if LANG=C", {