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

Allow feedback on unparsable unicode characters to render without i18next #765

Merged
merged 4 commits into from
Mar 9, 2023

Conversation

rossellhayes
Copy link
Contributor

@rossellhayes rossellhayes commented Mar 8, 2023

Pre-interpolate message generated by unparsable_unicode_message() so feedback is comprehensible when i18next is unavailable.

Previously, if i18next was unavailable, the feedback would contain uninterpolated strings, like this:

It looks like your R code contains an unexpected special character ({{character}}) that makes your code invalid.
{{code}}
Sometimes your code may contain a special character that looks like a regular character, especially if you copy and paste the code from another app. You can try replacing the code on that line with the following. There may be other places that need to be fixed, too.
{{suggestion}}

This PR adds a dependency on glue, which provides an elegant way to pre-interpolate the string, but isn't strictly necessary. If we'd like to avoid adding a dependency, I can refactor to just use regex.

PR task list:

  • Update NEWS
  • Add tests (if possible)
  • Update documentation with devtools::document()

…is comprehensible when `i18next` is unavailable
@rossellhayes rossellhayes added the type: bug Maintainers have validated that it is a real bug in the project code label Mar 8, 2023
@rossellhayes rossellhayes self-assigned this Mar 8, 2023
@gadenbuie
Copy link
Member

This PR adds a dependency on glue, which provides an elegant way to pre-interpolate the string, but isn't strictly necessary. If we'd like to avoid adding a dependency, I can refactor to just use regex.

Yeah that is elegant but let's use the same method we used in the other functions and not add the new dependency

@rossellhayes
Copy link
Contributor Author

Got it, refactored to use sub() instead

Copy link
Member

@gadenbuie gadenbuie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you!

Comment on lines +1174 to +1182
expect_unparsable_message <- function(user_code, problem, key) {
ex <- mock_exercise(user_code = user_code)
feedback <- evaluate_exercise(ex, new.env())$feedback
expect_equal(feedback, exercise_check_code_is_parsable(ex)$feedback)
expect_match(feedback$message, regexp = key, fixed = TRUE)
for (character in problem) {
expect_match(feedback$message, regexp = character, fixed = TRUE)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This cleans up the code quite a bit

@@ -4,6 +4,8 @@

- The embedded Ace editor used in learnr exercises now defaults to a tab width of 2, aligning with the Tidyverse style guide (#761).

- Add a fallback to generate a comprehensible English feedback message for code that fails to parse because it contains non-ASCII characters. Previously, if i18next was unavailable, the feedback would contain uninterpolated i18next markup. Now the feedback is pre-interpolated so students will always see a comprehensible message (#765).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can trim this down a little bit

Suggested change
- Add a fallback to generate a comprehensible English feedback message for code that fails to parse because it contains non-ASCII characters. Previously, if i18next was unavailable, the feedback would contain uninterpolated i18next markup. Now the feedback is pre-interpolated so students will always see a comprehensible message (#765).
- learnr now pre-renders (in English) the feedback message it provides when non-ASCII characters are included in submitted unparsable R code. This makes the feedback useful in places where learnr's in-browser translations aren't available (#765).

@rossellhayes rossellhayes merged commit 7648a1f into main Mar 9, 2023
@rossellhayes rossellhayes deleted the fix/interpolate-unparsable_unicode_message branch March 9, 2023 17:26
gadenbuie added a commit that referenced this pull request Mar 10, 2023
Applies suggestion from #765
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Maintainers have validated that it is a real bug in the project code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants