sensei icon indicating copy to clipboard operation
sensei copied to clipboard

WPML: Translate quizzes with questions

Open merkushin opened this issue 1 year ago • 6 comments

Resolves #5841

In this PR we don't address an issue of not working properly question translation: when you translated a question in a lesson, but the question remain containing the original content.

Proposed Changes

  • Create translations (duplicates) for quizzes and questions.
  • Updated properties.
  • Configure blocks.
  • The PR also contains some code style fixes.

Testing Instructions

  • Enable WPML
  • Create a course with lessons, quizzes and questions.
  • Create a translation for the course.
  • Make sure lessons were "translated" and contain quizzes.
  • Make sure you see duplicated questions for the target language (copies of original).
  • Go to the frontend and try take the test.
  • Now go back to WP Admin -> Sensei LMS -> Lessons.
  • Create a lesson without assigning it to a course. Add a quiz with a question(s).
  • Create a translation for this lesson.
  • Make sure you see a translated lesson in the target language, and a duplicate for the question(s).

New/Updated Hooks

  • sensei_rest_api_lesson_quiz_created - Fires after a quiz is created via the REST API.
  • sensei_lesson_quiz_created - Fires after a quiz is created while saving a lesson in a non-block editor.

Deprecated Code

  • Sensei_WPML - replaced with Sensei\WPML\WPML.

Pre-Merge Checklist

  • [x] PR title and description contain sufficient detail and accurately describe the changes
  • [ ] Acceptance criteria is met
  • [x] Decisions are publicly documented
  • [x] Adheres to coding standards (PHP, JavaScript, CSS, HTML)
  • [ ] All strings are translatable (without concatenation, handles plurals)
  • [x] Follows our naming conventions (P6rkRX-4oA-p2)
  • [x] Hooks (p6rkRX-1uS-p2) and functions are documented
  • [ ] New UIs are responsive and use a mobile-first approach
  • [ ] New UIs match the designs
  • [ ] Different user privileges (admin, teacher, subscriber) are tested as appropriate
  • [ ] Legacy courses (course without blocks) are tested
  • [x] Code is tested on the minimum supported PHP and WordPress versions
  • [ ] User interface changes have been tested on the latest versions of Chrome, Firefox and Safari
  • [ ] "Needs Documentation" label is added if this change requires updates to documentation
  • [ ] Known issues are created as new GitHub issues

merkushin avatar Feb 09 '24 17:02 merkushin

WordPress Dependencies Report

The github-action-wordpress-dependencies-report action has detected some script changes between the commit eaa97335c5da1e1759fbd1e7b0b8693d217a9f4b and trunk. Please review and confirm the following are correct before merging.

No changes detected in the current commit. But the comment was left so it is possible to check for the edit history.

This comment was automatically generated by the github-action-wordpress-dependencies-report action.

github-actions[bot] avatar Feb 12 '24 14:02 github-actions[bot]

Codecov Report

Attention: Patch coverage is 71.07438% with 140 lines in your changes are missing coverage. Please review.

Project coverage is 51.94%. Comparing base (9c9bcae) to head (eaa9733). Report is 24 commits behind head on trunk.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##              trunk    #7480    +/-   ##
==========================================
  Coverage     51.93%   51.94%            
- Complexity    11267    11310    +43     
==========================================
  Files           630      639     +9     
  Lines         47665    47821   +156     
  Branches        420      421     +1     
==========================================
+ Hits          24756    24840    +84     
- Misses        22572    22644    +72     
  Partials        337      337            
Files Coverage Δ
includes/class-sensei-course-structure.php 91.89% <100.00%> (+0.01%) :arrow_up:
...i/class-sensei-rest-api-lesson-quiz-controller.php 93.65% <98.13%> (+0.02%) :arrow_up:
includes/wpml/class-sensei-wpml.php 0.00% <0.00%> (-77.34%) :arrow_down:
includes/wpml/class-lesson-translation.php 73.91% <73.91%> (ø)
includes/wpml/class-wpml.php 0.00% <0.00%> (ø)
includes/wpml/class-course-translation.php 78.78% <78.78%> (ø)
includes/wpml/class-email.php 0.00% <0.00%> (ø)
includes/wpml/class-language-details.php 87.03% <87.03%> (ø)
includes/class-sensei.php 24.94% <35.71%> (-0.06%) :arrow_down:
includes/wpml/trait-quiz-translation-helper.php 52.00% <52.00%> (ø)
... and 4 more

... and 2 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 790e451...eaa9733. Read the comment docs.

codecov[bot] avatar Feb 12 '24 15:02 codecov[bot]

Thank for your review @renatho! I'll test it in a fresh environment to check the issues with the lesson order and the course opening. For the question category, I'll create a separate issue, probably.

Update. I created an issue for question categories: https://github.com/Automattic/sensei/issues/7537

merkushin avatar Feb 23 '24 12:02 merkushin

@renatho

I realized that when duplicating the course, it created the lessons in the reverse order. In my test in the other PR I tried to order the lessons so maybe it only happens when we don't order them?

Can't reproduce it for "unordered" lessons (when order hasn't been changed). But when I changed the order of the lessons and then translated the course, order remained unchanged in the translated course.

Looking into it...

merkushin avatar Mar 13 '24 05:03 merkushin

Test the previous changes of this PR with WordPress Playground.

github-actions[bot] avatar Mar 14 '24 05:03 github-actions[bot]

@renatho I've fixed the lesson order for "translated" lessons here: https://github.com/Automattic/sensei/pull/7480/commits/14466619dfd275a029db733ea4dde4eac36fbaa0 I had implemented the order inside modules, and probably decided later it works for other lessons 🙈 Could you try it one more time? Thanks!

Update Eventually, while testing re-usable progress, I encountered the behaviour you described. I didn't order lesson, but in the translated course they appeared reversed. Not cool at all, looking for a solution...

merkushin avatar Mar 14 '24 05:03 merkushin