Created
October 4, 2020 16:05
-
-
Save eliocamp/b2b82f9c3c622964696c5b308c9ae108 to your computer and use it in GitHub Desktop.
Code to try to translate learnr's UI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tutorial.js <- system.file("lib", "tutorial", "tutorial.js", package = "learnr") | |
tutorial_format.js <- system.file("rmarkdown", "templates", "tutorial", "resources", "tutorial-format.js", package = "learnr") | |
changes <- list( | |
run_code = list( | |
text = "Correr Código", | |
file = tutorial.js, | |
pattern = 'var run_button = add_submit_button("fa-play", "btn-success",', | |
code = 'var run_button = add_submit_button("fa-play", "btn-success", "{text}", false)' | |
), | |
submit_answer = list( | |
text = "Responder", | |
file = tutorial.js, | |
pattern = 'add_submit_button("fa-check-square-o", "btn-primary",', | |
code = 'add_submit_button("fa-check-square-o", "btn-primary", "{text}", true);' | |
), | |
start_over = list( | |
text = "Borrar todo", | |
file = tutorial.js, | |
pattern = 'var startOverButton = addHelperButton("fa-refresh",', | |
code = 'var startOverButton = addHelperButton("fa-refresh", "{text}");' | |
), | |
next_topic = list( | |
text = "Siguiente tema", | |
file = tutorial_format.js, | |
pattern = 'var nextButton = $(\'<button class="btn btn-primary">', | |
code = 'var nextButton = $(\'<button class="btn btn-primary">{text}</button>\');' | |
), | |
continue = list( | |
text = "Continuar", | |
file = tutorial_format.js, | |
pattern = 'var continueButton = ', | |
code = 'var continueButton = $(\'<button class="btn btn-default skip" data-section-id="\' + sectionElement.id + \'">{text}</button>\');' | |
), | |
hint = list( | |
text = "Ayuda", | |
file = tutorial.js, | |
pattern = 'var button = addHintButton("', | |
code = 'var button = addHintButton("{text}");' | |
), | |
clipboard = list( | |
text = "Copiar al portapapeles", | |
file = tutorial.js, | |
pattern = 'copyButton.append("', | |
code = 'copyButton.append(" {text}");' | |
) | |
) | |
make_changes <- function(change) { | |
file <- change$file | |
lines <- readLines(file) | |
code <- glue::glue_data(change, change$code) | |
where <- grepl(change$pattern, lines, fixed = TRUE) | |
lines[where] <- code | |
writeLines(lines, file) | |
return(which(where)) | |
} | |
lapply(changes, make_changes) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment