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

Add Value::maketext() subroutine to Value::WeBWorK.pm #298

Closed
wants to merge 1 commit into from

Conversation

mgage
Copy link
Member

@mgage mgage commented May 25, 2017

Use as
Value::maketext(…text to be translated …. )

inside pg/lib .pm files

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');
Copy link
Member

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?

Copy link
Member Author

@mgage mgage May 25, 2017

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;
}

Copy link
Member Author

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.

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 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.

@mgage
Copy link
Member Author

mgage commented Jun 6, 2017

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.

@mgage mgage closed this Jun 6, 2017
@mgage mgage deleted the develop_maketext_fix branch June 25, 2017 15:01
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