Skip to content

Add support for setting text language and direction of the generated HTML page and the DIV containing the problems#67

Merged
drdrew42 merged 2 commits into
drdrew42:masterfrom
taniwallach:add-lang-and-dir-support
Aug 19, 2021
Merged

Add support for setting text language and direction of the generated HTML page and the DIV containing the problems#67
drdrew42 merged 2 commits into
drdrew42:masterfrom
taniwallach:add-lang-and-dir-support

Conversation

@taniwallach
Copy link
Copy Markdown
Contributor

Copy lib/WeBWorK/Utils/LanguageAndDirection.pm from https://github.com/openwebwork/webwork2 which provides support for setting page level and problem level language and text direction based on the course/request language and settings provided by the PG file.

Have RenderApp/Controller/FormatRenderedProblem.pm use that, where we always force the "choice" for the main HTML page language based on the request parameter "language" (instead of a course setting) and attempt to use the language/direction requested by a PG problem, falling back to English and LTR, as the OPL needs that.

Problems which need a language or direction set should use:

  • SET_PROBLEM_LANGUAGE() and/or
  • SET_PROBLEM_TEXTDIRECTION()

A screenshot of a Hebrew PG problem (formatted from right-to-left, as needed) when the English feedback messages are in use (just the change from this PR): Sample-RTL-with-English-Feedback-Standalone-Renderer

A screenshot when the Hebrew feedback messages from #66 are also in use:
Sample-RTL-with-Hebrew-Feedback-Standalone-Renderer


Here is a sample PG problem which can be used to test this:

# Local notes:
# Based on Library/CollegeOfIdaho/setAlgebra_05_04_FactoringTrinomials/54IntAlg_27_FactorTrinomial.pg
# Translated to Hebrew and modified by Nathan Wallach, March 2019
###DESCRIPTION
## Factoring Trinomials
##
##ENDDESCRIPTION
## DBsubject(Algebra)
## DBchapter(Factoring)
## DBsection(Factoring trinomials)
## Institution(Technion)
## Author(RA Cruz, Nathan Wallach)
## Level(3)
## KEYWORDS('factoring')
## Date: 2019/03

DOCUMENT(); # This should be the first executable line in the problem.

loadMacros(
  "PGstandard.pl",
  "MathObjects.pl",
  "CofIdaho_macros.pl",
  "AnswerFormatHelp.pl",
  "PGcourse.pl"
);

SET_PROBLEM_TEXTDIRECTION("rtl");
SET_PROBLEM_LANGUAGE("he-IL");

TEXT(beginproblem());

######################################
#  Setup

$a = list_random(3,5,7);

$polynomial = Formula("x^3 + x^2 - ($a)^2 x - ($a)^2")->reduce->TeX;

######################################
#  Main text

BEGIN_TEXT
פרקו את הפולינום  \( $polynomial \)
כמכפלה של גורמים לינארים מהצורה  \( (x \pm \alpha) \).
$PAR
\{ openSpan( { "dir" => "ltr" } ) \}
\( $polynomial = \) \{ ans_rule(30) \}
\{ closeSpan() \}
$BR
${BBOLD}הנחיות להזנת התשובה${EBOLD}, עקב אילוצי תוכנת הבדיקה:
$BR
$SPACE$SPACE 1. אסור לרשום בתשובה לשאלה זו גורם מהצורה \( (x - (- \alpha) ) \)
   ויש לרשום במקום בצורה \( (x + \alpha ) \).
$BR
$SPACE$SPACE 2. \{ AnswerFormatHelp("formulas","הנחיות להזנת פונקציות") \}
END_TEXT

######################################
#  Answer

$answer="(x-$a) * (x + $a) * (x + 1)";
ANS(FactoringEvaluator($answer,"x"));

$showPartialCorrectAnswers = 1;

######################################
ENDDOCUMENT();

from https://github.com/openwebwork/webwork2
which provides support for setting page level and problem level
language and text direction based on the course/request language
and settings provided by the PG file.

Have RenderApp/Controller/FormatRenderedProblem.pm use that,
where we always force the "choice" for the main HTML page language
based on the request parameter "language" (instead of a course
setting) and attempt to use the language/direction requested by
a PGproblem, falling back to English and LTR, as the OPL need that.

Problems which need a language or direction set should use:
SET_PROBLEM_LANGUAGE() and/or SET_PROBLEM_TEXTDIRECTION()
@taniwallach taniwallach requested a review from drdrew42 as a code owner August 12, 2021 14:50
Copy link
Copy Markdown
Owner

@drdrew42 drdrew42 left a comment

Choose a reason for hiding this comment

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

🥇

@drdrew42 drdrew42 merged commit 07b241a into drdrew42:master Aug 19, 2021
@taniwallach taniwallach deleted the add-lang-and-dir-support branch August 20, 2021 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants