-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
Add Value::maketext() subroutine to Value::WeBWorK.pm #298
Conversation
Use as Value::maketext(…text to be translated …. ) inside pg/lib .pm files
@@ -73,6 +73,11 @@ sub Value::Formula::PGseedRandom { | |||
} | |||
sub Value::Formula::PGgetRandom {shift->{PGrandom}->random(@_)} | |||
|
|||
sub Value::maketext { | |||
my $envir =eval('$main::rh_envir'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand the need for eval
. Is that really necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so. The Value::WeBWorK.pm file is evaluated at compile time when the child is launched. Each request is handled within a new Safe compartment which changes the value of $main (in addition the contents of the environment variable $rh_envir is different for every request).
This is also how Davide handled the initialization of $envir for context a few lines above in WeBWorK.pm
my $self = shift;
my $context = Value::Context::copy($self,@_);
return $context unless $Parser::installed; # only do WW initialization after parser is fully loaded
return $context if $context->{WW} && scalar(keys %{$context->{WW}}) > 0;
my $envir = eval('\\%main::envir');
return $context unless $envir && scalar(keys(%{$envir})) > 0;
my $ww = $context->{WW} = {}; push @{$context->{data}{values}}, 'WW';
return $context if $Value::_no_WeBWorK_; # hack for command-line debugging
foreach my $x (@wwEvalFields) {$context->{WW}{$x} = $envir->{$x}}
$context->flags->set(
tolerance => $ww->{numRelPercentTolDefault} / 100,
zeroLevel => $ww->{numZeroLevelDefault},
zeroLevelTol => $ww->{numZeroLevelTolDefault},
num_points => $ww->{functNumOfPoints} + 2,
max_adapt => $ww->{functMaxConstantOfIntegration},
useBaseTenLog => $ww->{useBaseTenLog},
);
$context->{format}{number} = $ww->{numFormatDefault} if $ww->{numFormatDefault} ne '';
$context;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should hold off accepting this pull request until we decide how to handle localization within MathObjects. As Davide points out in #300 there may be a better way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the eval
in the code you quote is used for error trapping (in case %main::envir
doesn't exist -- I do testing in perl outside of WeBWorK proper). I don't think the eval()
has to do with the Safe compartment issues, here. But it has been a long time since I worked on this part of the code.
I'm going to remove this pull request for now. We'll revisit this when we decide on the best way to translate the phrases inside MathObjects. |
Use as
Value::maketext(…text to be translated …. )
inside pg/lib .pm files