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

[pull] main from carpentries:main #13

Merged
merged 22 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2f68768
refactor test-translate
zkamvar Dec 15, 2023
2e0fcd2
rearrange tests in page types
zkamvar Dec 15, 2023
dc0d211
add helpers for title elements; test 404 page
zkamvar Dec 15, 2023
0349a41
add tests for navigation
zkamvar Dec 15, 2023
8e11604
Merge pull request #558 from carpentries/refactor-translation-tests
zkamvar Dec 15, 2023
7f3ac97
first working refactor of centralising translation
zkamvar Dec 16, 2023
9be8430
use cached translations inside of utils-translate
zkamvar Dec 16, 2023
14ee25a
apply translations during setup
zkamvar Dec 18, 2023
bf4373a
simplify translation pre-compute; re-add tests
zkamvar Dec 18, 2023
465b6e0
centralise translate list; add documentation
zkamvar Dec 18, 2023
dfcf7ab
fix manual page for translations
zkamvar Dec 18, 2023
fa072c1
Merge pull request #559 from carpentries/refactor-translations
zkamvar Dec 18, 2023
6aac82d
add tr_ helpers; update tests
zkamvar Dec 19, 2023
1fbf3e0
update line numbers in translations
zkamvar Dec 19, 2023
7ae9c18
test translations using keys not values
zkamvar Dec 19, 2023
8406e7a
replace raw trans env calls with helper functions
zkamvar Dec 19, 2023
f992d4a
update documentation
zkamvar Dec 19, 2023
a33a128
clean up and document tests a bit
zkamvar Dec 19, 2023
1529dfd
Merge pull request #560 from carpentries/finalise-translate-tests
zkamvar Dec 19, 2023
936cf08
update metadata to include language
zkamvar Dec 19, 2023
155efd6
bump version to 0.16.2
zkamvar Dec 19, 2023
ed0bd3f
Merge pull request #561 from carpentries/release-0.16.2
zkamvar Dec 19, 2023
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 DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: sandpaper
Title: Create and Curate Carpentries Lessons
Version: 0.16.1
Version: 0.16.2
Authors@R: c(
person(given = "Zhian N.",
family = "Kamvar",
Expand Down
25 changes: 25 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
# sandpaper 0.16.2 (2023-12-19)

## MISC

* JSON metadata now contains the `inLanguage` key.

## DOCUMENTATION

* A list of translatable strings has now been added to
`vignette("translations", package = "sandpaper")`

## INTERNAL

* Translation strings now are unduplicated and live in a single file
(`R/utils-translate.R`). This will make finding and updating these strings
easier for maintainer and translators.
* Translations now live in the global environment called `these$translations`
* A new documentation page called `?translate` contains details of how
translations of template elements are rendered.
- `tr_src()` helper function provides access to the source strings of the
translations.
- `tr_get()`, `tr_varnish()`, and `tr_computed()` helper functions provide
access top the lists of translated strings. These have replaced the `tr_()`
strings at the point of generation.

# sandpaper 0.16.1 (2023-12-14)

## BUG FIX
Expand Down
2 changes: 1 addition & 1 deletion R/build_404.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ build_404 <- function(pkg, quiet = FALSE) {
this_dat <- list(
this_page = "404.html",
body = html,
pagetitle = tr_("Page not found")
pagetitle = tr_computed("PageNotFound")
)
page_globals$instructor$update(this_dat)
page_globals$learner$update(this_dat)
Expand Down
2 changes: 1 addition & 1 deletion R/build_aio.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ build_aio <- function(pkg, pages = NULL, quiet = FALSE) {
build_agg_page(
pkg = pkg,
pages = pages,
title = tr_("All in One View"),
title = tr_computed("AllInOneView"),
slug = "aio",
aggregate = "*",
prefix = TRUE,
Expand Down
3 changes: 2 additions & 1 deletion R/build_episode.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ get_nav_data <- function(path_md, path_src = NULL, home = NULL,
pf_title <- NULL

if (!is.null(page_back)) {
pb_title <- if (page_back == "index.md") tr_("Home") else get_trimmed_title(page_back)
trhome <- tr_varnish("Home")
pb_title <- if (page_back == "index.md") trhome else get_trimmed_title(page_back)
page_back <- as_html(page_back)
}
if (!is.null(page_forward)) {
Expand Down
7 changes: 4 additions & 3 deletions R/build_home.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ build_home <- function(pkg, quiet, next_page = NULL) {
needs_title <- nav$pagetitle == ""

if (needs_title) {
nav$pagetitle <- tr_("Summary and Schedule")
nav$pagetitle <- tr_computed("SummaryAndSchedule")
}
nav$page_forward <- as_html(nav$page_forward, instructor = TRUE)
page_globals$instructor$update(nav)
Expand All @@ -55,7 +55,7 @@ build_home <- function(pkg, quiet, next_page = NULL) {
page_globals$instructor$set("setup", use_instructor(setup))

if (needs_title) {
nav$pagetitle <- tr_("Summary and Setup")
nav$pagetitle <- tr_computed("SummaryAndSetup")
}
nav$page_forward <- as_html(nav$page_forward)
page_globals$learner$update(nav)
Expand Down Expand Up @@ -97,7 +97,8 @@ format_syllabus <- function(syl, use_col = TRUE) {
)
}
td1 <- glue::glue(td_template, cls = "col-md-2", thing = syl$timings)
td2 <- glue::glue(td_template, cls = "col-md-3", thing = c(links, tr_("Finish")))
td2 <- glue::glue(td_template, cls = "col-md-3",
thing = c(links, tr_computed("Finish")))
td3 <- glue::glue(td_template, cls = "col-md-7", thing = syl$questions)
out <- glue::glue_collapse(glue::glue("<tr>{td1}{td2}{td3}</tr>"), sep = "\n")
tmp <- tempfile(fileext = ".md")
Expand Down
7 changes: 4 additions & 3 deletions R/build_images.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ build_images <- function(pkg, pages = NULL, quiet = FALSE) {
build_agg_page(
pkg = pkg,
pages = pages,
title = tr_("All Images"),
title = tr_computed("AllImages"),
slug = "images",
aggregate = "/img/..",
prefix = FALSE,
Expand Down Expand Up @@ -46,7 +46,8 @@ make_images_section <- function(name, contents, parent) {
content <- contents[[element]]
alt <- xml2::xml_text(xml2::xml_find_all(content, "./img/@alt"))
n <- length(alt)
xml2::xml_add_child(section, "h3", glue::glue(tr_("Figure {element}")),
xml2::xml_add_child(section, "h3",
glue::glue(tr_computed("Figure")),
id = glue::glue("{name}-figure-{element}")
)
for (i in seq_along(alt)) {
Expand All @@ -57,7 +58,7 @@ make_images_section <- function(name, contents, parent) {
if (txt == "") {
txt <- "[decorative]"
}
desc <- glue::glue(tr_("Image {i} of {n}: {sQuote(txt)}"))
desc <- glue::glue(tr_computed("ImageOf"))
xml2::xml_add_child(section, "p", "aria-hidden" = "true", desc)
}
xml2::xml_add_child(section, contents[[element]])
Expand Down
5 changes: 3 additions & 2 deletions R/build_instructor_notes.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ build_instructor_notes <- function(pkg, pages = NULL, built = NULL, quiet) {
this_dat <- list(
this_page = "instructor-notes.html",
body = use_instructor(html),
pagetitle = tr_("Instructor Notes")
pagetitle = tr_varnish("InstructorNotes")
)

page_globals$instructor$update(this_dat)
Expand Down Expand Up @@ -135,7 +135,8 @@ make_instructor_note_linkback <- function(node, name) {
title <- trimws(xml2::xml_text(node))
id <- xml2::xml_attr(node, "id")
newid <- glue::glue("{name}-{id}")
anchor <- glue::glue("<a class='anchor' aria-label='{tr_('anchor')}' href='#{newid}'></a>")
tranchor <- tr_computed("Anchor")
anchor <- glue::glue("<a class='anchor' aria-label='{tranchor}' href='#{newid}'></a>")
new <- "<h3><a href='{name}.html#{id}'>{title}</a>{anchor}</h3>"
node <- xml2::read_xml(glue::glue(new))
xml2::xml_set_attr(node, "id", newid)
Expand Down
2 changes: 1 addition & 1 deletion R/build_keypoints.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ build_keypoints <- function(pkg, pages = NULL, quiet = FALSE) {
build_agg_page(
pkg = pkg,
pages = pages,
title = tr_("Key Points"),
title = tr_varnish("KeyPoints"),
slug = "key-points",
aggregate = "/div[starts-with(@id, 'keypoints')]/div[@class='callout-inner']/div[@class='callout-content']/*",
prefix = FALSE,
Expand Down
2 changes: 1 addition & 1 deletion R/build_profiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build_profiles <- function(pkg, quiet) {
this_dat <- list(
this_page = "profiles.html",
body = use_instructor(html),
pagetitle = tr_("Learner Profiles")
pagetitle = tr_varnish("LearnerProfiles")
)
page_globals$instructor$update(this_dat)

Expand Down
1 change: 0 additions & 1 deletion R/build_site.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ build_site <- function(path = ".", quiet = !interactive(), preview = TRUE, overr
# Here we provision our website using pkgdown and either initialise it if it
# does not exist or update the CSS, HTML, and JS if it does exist.
pkg <- pkgdown::as_pkgdown(path_site(path), override = override)
set_language(this_metadata$get()[["lang"]])
built_path <- fs::path(pkg$src_path, "built")
# NOTE: This is a kludge to prevent pkgdown from displaying a bunch of noise
# if the user asks for quiet.
Expand Down
1 change: 1 addition & 0 deletions R/utils-metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ fill_metadata_template <- function(meta) {
if (endsWith(local_meta$url, "/")) {
local_meta$url <- paste0(local_meta$url, "index.html")
}
local_meta$lang <- sub("_", "-", local_meta$lang %||% "en")
title <- local_meta$pagetitle
if (grepl("<", title, fixed = TRUE)) {
local_meta$pagetitle <- xml2::xml_text(xml2::read_html(title))
Expand Down
Loading