Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6892a6c
PoC internationalization
ColinFay Sep 30, 2020
cc14a86
Added html deps
ColinFay Oct 1, 2020
c3e0bda
libs and example
ColinFay Oct 1, 2020
70852d9
This implement the internationalization of learnr UI
ColinFay Oct 7, 2020
1888d7e
documentation of the new param
ColinFay Oct 7, 2020
f87c89e
more info in the vignette
ColinFay Oct 7, 2020
83d0854
rm language from sandbox.Rmd
ColinFay Oct 7, 2020
10464cd
html dep is written in a tempfile
ColinFay Oct 13, 2020
6463547
bootbox is now internationalized
ColinFay Oct 13, 2020
24af04b
Added a note about bootbox
ColinFay Oct 13, 2020
e4b0a99
Update R/html-dependencies.R
ColinFay Oct 19, 2020
621c9b4
Extend internationalization to expose customization to authors
gadenbuie Dec 23, 2020
8c38979
Rewrite multilang vignette
gadenbuie Dec 23, 2020
4e74ca6
Fix namespacing learnr functions in vignette/multilang
gadenbuie Dec 23, 2020
2a30ba3
Escape all unicode characters
gadenbuie Dec 23, 2020
7af49e9
Backport dQuote() with q argument
gadenbuie Dec 23, 2020
2159e63
Check submit button parent element for data-check attribute
gadenbuie Dec 28, 2020
878f5ae
Fix use of dQuote in multilang vignette
gadenbuie Dec 28, 2020
fc8dc5d
Refactor internationalization
gadenbuie Jan 12, 2021
359fa1f
Add note that only first language is used
gadenbuie Jan 12, 2021
17a2430
Add localize method to window.tutorial
gadenbuie Jan 12, 2021
5d53ccd
Rename and update sandbox demo
gadenbuie Jan 12, 2021
7db49a9
Remove unused backport of dQuote()
gadenbuie Jan 12, 2021
7ef80fc
More cleaning up of sandbox
gadenbuie Jan 12, 2021
be28f46
Add "localize" shiny message handler
gadenbuie Jan 12, 2021
b1a6044
Add translation capability to question buttons
gadenbuie Jan 12, 2021
5167298
Only localize default question button labels
gadenbuie Jan 12, 2021
4571848
Fix mime type of script tag containing json
gadenbuie Jan 13, 2021
622f9ea
Add notes about motivation in comments
gadenbuie Jan 13, 2021
a546490
Explicitly point to vignette() in language param docs
gadenbuie Jan 13, 2021
a46069f
Use arrays in i18next.t() to provide fallback and add translation for…
gadenbuie Jan 13, 2021
649d04a
Add news for #456
gadenbuie Jan 13, 2021
95748fa
Don't use "custom" namespace, instead customizations overwrite defaul…
gadenbuie Jan 15, 2021
d885520
learnr-i18n-init.js -> tutorial-i18n-init.js
gadenbuie Jan 15, 2021
2ac6219
Use ES5 compatible syntax
gadenbuie Jan 15, 2021
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
Prev Previous commit
Next Next commit
Add translation capability to question buttons
- button.questionsubmit and button.questiontryagain
- localizes after UI output changes
  • Loading branch information
gadenbuie committed Jan 12, 2021
commit b1a60449c3f3f79735cefc84402991d68254e0ab
14 changes: 10 additions & 4 deletions R/i18n.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ i18n_translations <- function() {
continue = "Continue",
submitanswer = "Submit Answer",
previoustopic = "Previous Topic",
nexttopic = "Next Topic"
nexttopic = "Next Topic",
questionsubmit = "Submit Answer",
questiontryagain = "Try Again"
),
text = list(
startover = "Start Over",
Expand All @@ -148,8 +150,10 @@ i18n_translations <- function() {
startover = "Recommencer",
continue = "Continuer",
submitanswer = "Soumettre",
previoustopic = "Chapitre pr\u00e9c\u00e9dent",
nexttopic = "Chapitre Suivant"
previoustopic = "Chapitre Pr\u00e9c\u00e9dent",
nexttopic = "Chapitre Suivant",
questionsubmit = "Soumettre",
questiontryagain = "R\u00e9essayer"
),
text = list(
startover = "Recommencer",
Expand All @@ -168,7 +172,9 @@ i18n_translations <- function() {
continue = "\u2705",
submitanswer = "\U0001f197",
previoustopic = "\u2b05",
nexttopic = "\u27a1"
nexttopic = "\u27a1",
questionsubmit = "\U0001f197",
questiontryagain = "\U0001f501"
),
text = list(
startover = "\u23ee",
Expand Down
4 changes: 2 additions & 2 deletions R/quiz.R
Original file line number Diff line number Diff line change
Expand Up @@ -565,14 +565,14 @@ question_button_label <- function(question, label_type = "submit", is_valid = TR
action_button_id <- NS(question$ids$question)("action_button")

if (label_type == "submit") {
button <- actionButton(action_button_id, button_label, class = default_class)
button <- actionButton(action_button_id, button_label, class = default_class, `data-i18n` = "button.questionsubmit")
if (!is_valid) {
button <- disable_all_tags(button)
}
button
} else if (label_type == "try_again") {
mutate_tags(
actionButton(action_button_id, button_label, class = warning_class),
actionButton(action_button_id, button_label, class = warning_class, `data-i18n` = "button.questiontryagain"),
paste0("#", action_button_id),
function(ele) {
ele$attribs$class <- str_remove(ele$attribs$class, "\\s+btn-default")
Expand Down
5 changes: 5 additions & 0 deletions inst/lib/i18n/learnr-i18n-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ $(document).on("shiny:sessioninitialized", function() {
$(selector).localize(opts);
}

// localize question buttons when shown
$(document).on('shiny:value', '.tutorial-question', function(ev) {
setTimeout(function() { $(ev.target).localize() }, 0);
});

function localizeHandler(x) {
var selector,language;
if (
Expand Down
8 changes: 6 additions & 2 deletions sandbox/multilang.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ output:
runcode: Run!
hints: Hint!
startover: Redo!
questionsubmit: Let's See
questiontryagain: Retry
# es: tutorial_es.json
es:
button:
Expand All @@ -36,7 +38,6 @@ jsonlite::write_json(
```



```{r setup, include=FALSE}
library(learnr)
library(nycflights13)
Expand All @@ -61,7 +62,10 @@ tutorial_options(
This is the intro to the whole ball of wax.

```{r context="render"}
shiny::selectInput("language", "Choose a Language", choices = c("English" = "en", "French" = "fr", "Spanish" = "es"))
shiny::selectInput(
"language", "Choose a Language",
choices = c("English" = "en", "French" = "fr", "Spanish" = "es", "Emoji" = "emo")
)
```

```{r context="server"}
Expand Down