Skip to content

Commit

Permalink
Merge pull request #256 from r-lib/fix-language-test
Browse files Browse the repository at this point in the history
Set `LC_ALL` in translation test
  • Loading branch information
lionel- authored Sep 20, 2023
2 parents 28ab413 + f249eda commit 028b4d5
Showing 1 changed file with 10 additions and 2 deletions.
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`
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")
})

0 comments on commit 028b4d5

Please sign in to comment.