From 62d72cfbb326730bea1671995036e3d54a0498f0 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Mon, 8 Nov 2021 13:14:27 -0600 Subject: [PATCH] Use bindtextdomain() hack to reset cache --- R/po.R | 23 +++++------------------ tests/testthat/test-po.R | 3 --- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/R/po.R b/R/po.R index 7fa61530..d8e990ea 100644 --- a/R/po.R +++ b/R/po.R @@ -4,25 +4,12 @@ load_po <- function(package, path) { return() } - # Clean up previous copies - unlink(temp_po_dirs(package), recursive = TRUE, force = TRUE) + # Reset cache to avoid gettext() retrieving cached value + # See for details + bindtextdomain("reset", withr::local_tempdir()) - # Create new copy of translations in temp dir - tmp <- tempfile(temp_po_prefix(package)) - dir.create(tmp, showWarnings = FALSE) - tmp_po <- file.path(tmp, "po") - file.copy(po_path, tmp, recursive = TRUE) - - bindtextdomain(paste0("R-", package), tmp_po) # R level messages - bindtextdomain(package, tmp_po) # C level messages + bindtextdomain(paste0("R-", package), po_path) # R level messages + bindtextdomain(package, po_path) # C level messages invisible() } - -temp_po_prefix <- function(package) { - paste0("pkgload-po-", package, "-") -} - -temp_po_dirs <- function(package) { - dir(tempdir(), paste0("^", temp_po_prefix(package)), full.names = TRUE) -} diff --git a/tests/testthat/test-po.R b/tests/testthat/test-po.R index 8a9a9d82..cf0203aa 100644 --- a/tests/testthat/test-po.R +++ b/tests/testthat/test-po.R @@ -4,7 +4,4 @@ test_that("translation domain correctly loaded", { withr::local_envvar(LANGUAGE = "fr") expect_equal(hello(), "Bonjour") - - load_all(test_path("testTranslations")) - expect_equal(length(temp_po_dirs("testTranslations")), 1) })