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

WIP: Add Support for Translations #546

Merged
merged 90 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
fe7d872
document
joelnitta Nov 22, 2023
e0f460e
Add scaffolding to translate with PO files
joelnitta Nov 22, 2023
3b59e12
Flag strings for translation
joelnitta Nov 22, 2023
c34b7e1
Add POT file
joelnitta Nov 22, 2023
55a9af6
Add Japanese translations
joelnitta Nov 22, 2023
dfa3390
Add test for translations
joelnitta Nov 22, 2023
af5fe22
Use local_envvar_pkgdown() instead of section_init()
joelnitta Nov 23, 2023
f6a23fe
Delete un-needed functions
joelnitta Nov 23, 2023
457e14c
Remove superfluous line
joelnitta Nov 23, 2023
0c45501
Delete un-needed function
joelnitta Nov 23, 2023
94f247b
Insert translations for mustache elements
joelnitta Nov 24, 2023
de69eae
Add JA translations
joelnitta Nov 24, 2023
31876a4
allow translated vars to be included in site data
zkamvar Nov 27, 2023
ffcd994
fix typo
zkamvar Nov 27, 2023
1b64544
add translation terms that I found in varnish
zkamvar Nov 27, 2023
3862270
fix typo
zkamvar Nov 27, 2023
ef431f7
fix more typos
zkamvar Nov 27, 2023
5eb0acb
apply variables to translation strings
zkamvar Nov 27, 2023
f302a25
begin work on fine-tuning translated strings
zkamvar Nov 28, 2023
5634644
clean up varnish terms a bit
zkamvar Nov 28, 2023
57a4a86
re-run potools::po_extract()
zkamvar Nov 28, 2023
3bd6875
run potools::po_update() and fix fuzzy matches
zkamvar Nov 28, 2023
ef7de79
update variable names
zkamvar Nov 28, 2023
b8ad8cb
add lang attribute to pkgdown template
zkamvar Nov 28, 2023
900adfa
add fill_translation_vars function to glue data
zkamvar Nov 28, 2023
fd352e6
Add JA translations
joelnitta Nov 29, 2023
de96250
fix license text with hyperlink
zkamvar Nov 29, 2023
3a17e12
organising a bit more...
zkamvar Nov 30, 2023
9290d47
use for-loop for my gluing
zkamvar Nov 30, 2023
56e430a
use explainer variable
zkamvar Nov 30, 2023
6086fec
add mechanism to include HTML templating
zkamvar Nov 30, 2023
f514620
rerun potools suite and fix fuzzy messages in ja
zkamvar Nov 30, 2023
d647962
compile ja translations to confirm it works.
zkamvar Nov 30, 2023
00e8f30
fixed index sidebar item; add documentation
zkamvar Nov 30, 2023
be2c907
fix complex BuiltWith string and template license
zkamvar Dec 1, 2023
942bac3
fix url templating for specific case
zkamvar Dec 1, 2023
d082e99
rerender po files (there is still one fuzzy)
zkamvar Dec 1, 2023
2d820b8
Update JA translations
joelnitta Dec 1, 2023
ba4d4ff
update license translation string; anchor string
zkamvar Dec 1, 2023
efbca92
add translation for Overview;Objectives;Questions
zkamvar Dec 1, 2023
7d049c8
collect, update, and compile messages
zkamvar Dec 1, 2023
8a8fab9
add documentation for the lang config item
zkamvar Dec 1, 2023
4745196
add Joel as an author and translator
zkamvar Dec 1, 2023
2577c03
document
zkamvar Dec 1, 2023
a071280
add translate_callout_heading()
zkamvar Dec 1, 2023
58a4c64
update translations
zkamvar Dec 1, 2023
52c49da
Merged origin/main into joelnitta-translate
zkamvar Dec 1, 2023
dc78b26
bump version to dev; add news
zkamvar Dec 1, 2023
152c5ad
Update JA translations
joelnitta Dec 2, 2023
8a5f41f
add test for code blocks
zkamvar Dec 4, 2023
ba111d2
update fix_codeblocks to include translations
zkamvar Dec 4, 2023
2884de1
add translations for output blocks
zkamvar Dec 4, 2023
6a4ca89
fix small bug in apply_translations
zkamvar Dec 4, 2023
45fa492
add translations that we will implement in future
zkamvar Dec 4, 2023
0c72780
collect translations; add my attempt for SpanToTop
zkamvar Dec 4, 2023
87ff576
compile translations
zkamvar Dec 4, 2023
8fd705e
update and recompile translations for JS
zkamvar Dec 4, 2023
a860caf
add known_languages() function and `Toggle Menu`
zkamvar Dec 4, 2023
e965a5a
add test for aria menu items
zkamvar Dec 4, 2023
5141dad
update pofiles
zkamvar Dec 4, 2023
3e2a105
update DECRIPTION and NEWS with withr
zkamvar Dec 4, 2023
c44058b
begin work on vignette
zkamvar Dec 4, 2023
7bf25c9
add translations vignette to pkgdown
zkamvar Dec 4, 2023
a7d6b6d
add another paragraph
zkamvar Dec 4, 2023
a462e16
fix breaking tests
zkamvar Dec 5, 2023
a7e934f
ensure the translation vars are always set
zkamvar Dec 5, 2023
7fc90c2
document and add more stuff to vignette
zkamvar Dec 5, 2023
e474e7d
update vignette to be more informative
zkamvar Dec 5, 2023
6181754
update pkgdown
zkamvar Dec 5, 2023
b9ff1e1
Make elements of images section translatable
joelnitta Dec 5, 2023
af4c1a1
Add JA translations
joelnitta Dec 5, 2023
201c1de
use normal glue braces for translation templating
zkamvar Dec 5, 2023
5dcfd5d
update vignette
zkamvar Dec 5, 2023
2413d2a
skip when we are on lower versions of windows
zkamvar Dec 5, 2023
e6ee35b
update NEWS
zkamvar Dec 5, 2023
0678511
make it explicitly less than 4.2
zkamvar Dec 5, 2023
edb6050
skip {renv} test on macOS
zkamvar Dec 5, 2023
4c8a154
skip actual weird test on mac
zkamvar Dec 6, 2023
86d6413
move translating functions into utils-translate
zkamvar Dec 6, 2023
5f72ef3
apply further tests for translations
zkamvar Dec 6, 2023
4ccf515
create code to fix the accordions
zkamvar Dec 6, 2023
d9b76f9
add xml_text_translate(); use for accordions
zkamvar Dec 6, 2023
6c4a820
replace translate_callout_heading
zkamvar Dec 6, 2023
9b43fe1
extract and update translations
zkamvar Dec 6, 2023
fd3f86d
no need to skip on macos anymore
zkamvar Dec 6, 2023
265e4f8
Update JA translations
joelnitta Dec 6, 2023
0cf0919
remove skipper
zkamvar Dec 7, 2023
b82d3e0
change `local_envvar_pkgdown()` to `set_language()`
zkamvar Dec 7, 2023
5f080b2
add catch to not set unknown language
zkamvar Dec 7, 2023
1f51cf1
add some spanish translations
zkamvar Dec 7, 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
12 changes: 9 additions & 3 deletions 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.15.0
Version: 0.15.0.9000
Authors@R: c(
person(given = "Zhian N.",
family = "Kamvar",
Expand Down Expand Up @@ -44,6 +44,11 @@ Authors@R: c(
role = c("ctb"),
email = "[email protected]",
comment = c(ORCID = "0000-0001-9144-3701")),
person(given = "Joel H.",
family = "Nitta",
role = c("aut", "trl"),
email = "[email protected]",
comment = c(ORCID = "0000-0003-4719-7472")),
person())
Description: We provide tools to build a Carpentries-themed lesson repository
into an accessible standalone static website. These include local tools and
Expand All @@ -69,6 +74,7 @@ Imports:
renv (>= 0.14.0),
rprojroot,
usethis (>= 2.0.0),
withr,
whisker,
callr,
servr,
Expand All @@ -81,7 +87,6 @@ Suggests:
brio,
xml2,
xslt,
withr,
jsonlite,
sessioninfo,
mockr,
Expand All @@ -90,13 +95,14 @@ Additional_repositories: https://carpentries.r-universe.dev/
Remotes:
ropensci/tinkr,
carpentries/pegboard,
carpentries/varnish
carpentries/varnish@add-l10n-support
SystemRequirements: pandoc (>= 2.11.4) - https://pandoc.org
Encoding: UTF-8
LazyData: true
Config/testthat/edition: 3
Config/testthat/parallel: false
Config/Needs/check: rstudio/renv
Config/potools/style: explicit
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
URL: https://carpentries.github.io/sandpaper/, https://github.com/carpentries/sandpaper/, https://carpentries.github.io/workbench/
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export(get_instructors)
export(get_learners)
export(get_profiles)
export(get_syllabus)
export(known_languages)
export(manage_deps)
export(move_episode)
export(no_package_cache)
Expand Down
31 changes: 31 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
# sandpaper 0.15.0.9000 (unreleased)

## NEW FEATURES

* It is now possible to build lessons in languages other than English so that
the website elements are also localised to that language (reported: @zkamvar,
#205, @joelnitta, #544; fixed: @joelnitta and @zkamvar, #546).
* `known_languages()` is a function that will return the language codes that are
known by {sandpaper}.

## DOCUMENTATION

* A new vignette `vignette("translation", package = "sandpaper")` describes how
translation of template components works and how to submit new/update
translations.

## BUG FIX

* The spelling of keypoints is now consistent between the menu item and the
callout blocks (reported: @clarallebot,
https://github.com/carpentries/workbench/issues/44; fixed: @zkamvar, #546)

## DEPENDENCIES

* The {withr} package has been upgraded to an import from a suggested package.

## MISC

* Added @joelnitta as an author and translator


# sandpaper 0.15.0 (2023-11-29)

## NEW FEATURES
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 = "Page not found"
pagetitle = tr_("Page not found")
)
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 = "All in One View",
title = tr_("All in One View"),
slug = "aio",
aggregate = "*",
prefix = TRUE,
Expand Down
2 changes: 1 addition & 1 deletion R/build_episode.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ 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") "Home" else get_trimmed_title(page_back)
pb_title <- if (page_back == "index.md") tr_("Home") else get_trimmed_title(page_back)
page_back <- as_html(page_back)
}
if (!is.null(page_forward)) {
Expand Down
6 changes: 3 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 <- "Summary and Schedule"
nav$pagetitle <- tr_("Summary and Schedule")
}
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 <- "Summary and Setup"
nav$pagetitle <- tr_("Summary and Setup")
}
nav$page_forward <- as_html(nav$page_forward)
page_globals$learner$update(nav)
Expand Down Expand Up @@ -97,7 +97,7 @@ 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, "Finish"))
td2 <- glue::glue(td_template, cls = "col-md-3", thing = c(links, tr_("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
3 changes: 3 additions & 0 deletions R/build_html.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ build_html <- function(template = "chapter", pkg, nodes, global_data, path_md, q
# Process instructor page ----------------------------------------------------
update_sidebar(global_data$instructor, instructor_nodes, fs::path_file(this_page))
meta$set("url", paste0(base_url, this_page))
translated <- fill_translation_vars(global_data$instructor$get())
global_data$instructor$set("json", fill_metadata_template(meta))
global_data$instructor$set("translate", translated)
modified <- pkgdown::render_page(pkg,
template,
data = global_data$instructor$get(),
Expand All @@ -71,6 +73,7 @@ build_html <- function(template = "chapter", pkg, nodes, global_data, path_md, q

# Process learner page if needed ---------------------------------------------
if (modified) {
global_data$learner$set("translate", translated)
this_page <- as_html(this_page)
update_sidebar(global_data$learner, learner_nodes, fs::path_file(this_page))
meta$set("url", paste0(base_url, this_page))
Expand Down
6 changes: 3 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 = "All Images",
title = tr_("All Images"),
slug = "images",
aggregate = "/img/..",
prefix = FALSE,
Expand Down Expand Up @@ -46,7 +46,7 @@ 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("Figure {element}"),
xml2::xml_add_child(section, "h3", glue::glue(tr_("Figure {element}")),
id = glue::glue("{name}-figure-{element}")
)
for (i in seq_along(alt)) {
Expand All @@ -57,7 +57,7 @@ make_images_section <- function(name, contents, parent) {
if (txt == "") {
txt <- "[decorative]"
}
desc <- glue::glue("Image {i} of {n}: {sQuote(txt)}")
desc <- glue::glue(tr_("Image {i} of {n}: {sQuote(txt)}"))
xml2::xml_add_child(section, "p", "aria-hidden" = "true", desc)
}
xml2::xml_add_child(section, contents[[element]])
Expand Down
4 changes: 2 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 = "Instructor Notes"
pagetitle = tr_("Instructor Notes")
)

page_globals$instructor$update(this_dat)
Expand Down Expand Up @@ -135,7 +135,7 @@ 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='anchor' href='#{newid}'></a>")
anchor <- glue::glue("<a class='anchor' aria-label='{tr_('anchor')}' 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 = "Key Points",
title = tr_("Key Points"),
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 = "Learner Profiles"
pagetitle = tr_("Learner Profiles")
)
page_globals$instructor$update(this_dat)

Expand Down
1 change: 1 addition & 0 deletions R/build_site.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ 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
9 changes: 9 additions & 0 deletions R/set_dropdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ set_dropdown <- function(path = ".", order = NULL, write = FALSE, folder) {
#'
#' The following keypairs are known by sandpaper, but are optional:
#'
#' - **lang** `[character]` the [language
#' code](https://www.gnu.org/software/gettext/manual/html_node/Usual-Language-Codes.html)
#' that matches the language of the lesson content. This defaults to `"en"`,
#' but can be any language code (e.g. "ja" specifying Japanese) or
#' combination language code and [country
#' code](https://www.gnu.org/software/gettext/manual/html_node/Country-Codes.html)
#' (e.g. "pt_BR" specifies Pourtugese used in Brazil). For more information
#' on how this is used, see [the Locale Names section of the gettext
#' manual](https://www.gnu.org/software/gettext/manual/html_node/Locale-Names.html)
#' - **url** `[character]` custom URL if you are deploying to a URL that is not
#' the default github pages io domain.
#' - **fail_on_error** `[boolean]` for R Markdown lessons; fail the build if any
Expand Down
12 changes: 12 additions & 0 deletions R/utils-cli.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ warn_schedule <- function() {
cli::cli_end(thm)
}

warn_no_language <- function(lang) {
thm <- cli::cli_div(theme = sandpaper_cli_theme())
wmsg <- "{.code {siQuote(lang)}} is not a language that has been defined in The Workbench."
cli::cli_alert_warning(wmsg)
amsg1 <- "Use {.code known_languages()} to see a list of known languages"
cli::cli_alert_info(cli::style_dim(amsg1), class = "alert-suggestion")
amsg2 <- c("To add a new language, consult {.code vignette('translations', package = 'sandpaper')}")
cli::cli_alert_info(cli::style_dim(amsg2), class = "alert-suggestion")

cli::cli_end(thm)
}

show_changed_yaml <- function(sched, order, yaml, what = "episodes") {

# display for the user to distinguish what was added and what was taken
Expand Down
3 changes: 3 additions & 0 deletions R/utils-potools.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tr_ <- function(...) {
enc2utf8(gettext(paste0(...), domain = "R-sandpaper"))
joelnitta marked this conversation as resolved.
Show resolved Hide resolved
}
Loading