Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set LC_ALL in translation test #256

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/imports-env.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' package namespace environment, and is a child of `<namespace:base>`,
#' which is a child of `R_GlobalEnv`.
#' @keywords internal
#' @param path TODO: fix doc
#' @param package The package name as a string.
#' @seealso [ns_env()] for the namespace environment that
#' all the objects (exported and not exported).
#' @seealso [pkg_env()] for the attached environment that contains
Expand Down
2 changes: 1 addition & 1 deletion man/imports_env.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions tests/testthat/test-po.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@ test_that("translation domain correctly loaded", {
})

test_that("modified translations are correctly reloaded", {
# Need to also specify `LC_ALL` because `LANGUAGE` is ignored when
# `LANG` is set (here via `LC_ALL`) to `C` or `C.UTF-8`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this go upstream into withr too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the upstream change: r-lib/withr@687f3a3

It's only giving a warning as the caller needs to set the locale.

with_lang <- function(lc, language, expr) {
withr::local_envvar(c(LC_ALL = lc))
withr::local_language(language)
expr
}

pkg <- withr::local_tempdir()
file.copy(dir(test_path("testTranslations"), full.names = TRUE), pkg, recursive = TRUE)

# Load package and generate translation
load_all(pkg)
withr::defer(unload("testTranslations"))
withr::with_language("fr", hello())
with_lang("fr_FR", "fr", hello())

# Modify .po file
po_path <- file.path(pkg, "po", "R-fr.po")
Expand All @@ -33,5 +41,5 @@ test_that("modified translations are correctly reloaded", {

# Re-load and re-translate
load_all(pkg)
expect_equal(withr::with_language("fr", hello()), "Salut")
expect_equal(with_lang("fr_FR", "fr", hello()), "Salut")
})
Loading